Skip to content

Commit e053da4

Browse files
committed
Fix NRE in List_Var_Gui
- Also cleaned up code - Ref issue #17
1 parent a483007 commit e053da4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

WinNUT_V2/WinNUT_GUI/List_Var_Gui.vb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ Imports WinNUT_Client_Common
1111

1212
Public Class List_Var_Gui
1313
Private List_Var_Datas As List(Of UPS_List_Datas)
14-
Private LogFile As Logger
1514
Private UPS_Name = WinNUT.UPS_Device.Nut_Config.UPSName
15+
1616
Private Sub List_Var_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load
17-
' Me.LogFile = WinNUT.LogFile
1817
LogFile.LogTracing("Load List Var Gui", LogLvl.LOG_DEBUG, Me)
19-
Me.Icon = WinNUT.Icon
20-
Me.Visible = False
18+
Icon = WinNUT.Icon
19+
Visible = False
2120
PopulateTreeView()
22-
Me.Visible = True
21+
Visible = True
2322
End Sub
2423

2524
Private Sub PopulateTreeView()
@@ -34,14 +33,14 @@ Public Class List_Var_Gui
3433

3534
action = Sub() TView_UPSVar.Nodes.Clear()
3635
TView_UPSVar.Invoke(action)
37-
action = Sub() TView_UPSVar.Nodes.Add(WinNUT_Params.Arr_Reg_Key.Item("UPSName"), WinNUT_Params.Arr_Reg_Key.Item("UPSName"))
36+
action = Sub() TView_UPSVar.Nodes.Add(Arr_Reg_Key.Item("UPSName"), Arr_Reg_Key.Item("UPSName"))
3837
TView_UPSVar.Invoke(action)
3938
Dim TreeChild As New TreeNode
4039
Dim LastNode As New TreeNode
4140
For Each UPS_Var In List_Var_Datas
4241
LastNode = TView_UPSVar.Nodes(0)
4342
Dim FullPathNode = String.Empty
44-
For Each SubPath In (Strings.Split(UPS_Var.VarKey, "."))
43+
For Each SubPath In (Split(UPS_Var.VarKey, "."))
4544
FullPathNode += SubPath & "."
4645
Dim Nodes = TView_UPSVar.Nodes.Find(FullPathNode, True)
4746
If Nodes.Length = 0 Then
@@ -83,18 +82,18 @@ Public Class List_Var_Gui
8382
Dim SelectedNode As TreeNode = TView_UPSVar.SelectedNode
8483
If SelectedNode IsNot Nothing Then
8584
If SelectedNode.Parent IsNot Nothing Then
86-
If SelectedNode.Parent.Text <> Me.UPS_Name And SelectedNode.Nodes.Count = 0 Then
87-
Dim VarName = Strings.Replace(TView_UPSVar.SelectedNode.FullPath, Me.UPS_Name & ".", "")
85+
If SelectedNode.Parent.Text <> UPS_Name And SelectedNode.Nodes.Count = 0 Then
86+
Dim VarName = Replace(TView_UPSVar.SelectedNode.FullPath, UPS_Name & ".", "")
8887
LogFile.LogTracing("Update {VarName}", LogLvl.LOG_DEBUG, Me)
89-
Lbl_V_Value.Text = WinNUT.UPS_Device.GetUPSVar(VarName, Me.UPS_Name)
88+
Lbl_V_Value.Text = WinNUT.UPS_Device.GetUPSVar(VarName, UPS_Name)
9089
End If
9190
End If
9291
End If
9392
End Sub
9493

9594
Private Sub Btn_Close_Click(sender As Object, e As EventArgs) Handles Btn_Close.Click
9695
LogFile.LogTracing("Close List Var Gui", LogLvl.LOG_DEBUG, Me)
97-
Me.Close()
96+
Close()
9897
End Sub
9998

10099
Private Sub Btn_Reload_Click(sender As Object, e As EventArgs) Handles Btn_Reload.Click
@@ -103,13 +102,13 @@ Public Class List_Var_Gui
103102
Lbl_V_Value.Text = ""
104103
Lbl_D_Value.Text = ""
105104
TView_UPSVar.Nodes.Clear()
106-
Me.PopulateTreeView()
105+
PopulateTreeView()
107106
End Sub
108107

109108
Private Sub TView_UPSVar_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TView_UPSVar.NodeMouseClick
110109
Dim index As Integer = 0
111-
Dim UPSName = WinNUT_Params.Arr_Reg_Key.Item("UPSName")
112-
Dim SelectedChild = Strings.Replace(e.Node.FullPath, UPSName & ".", "")
110+
Dim UPSName = Arr_Reg_Key.Item("UPSName")
111+
Dim SelectedChild = Replace(e.Node.FullPath, UPSName & ".", "")
113112
Dim FindChild As Predicate(Of UPS_List_Datas) = Function(ByVal x As UPS_List_Datas)
114113
If x.VarKey = SelectedChild Then
115114
Return True
@@ -134,7 +133,7 @@ Public Class List_Var_Gui
134133
LogFile.LogTracing("Export TreeView To Clipboard", LogLvl.LOG_DEBUG, Me)
135134
Dim ToClipBoard As String = Nothing
136135
With WinNUT.UPS_Device.UPS_Datas
137-
ToClipBoard = WinNUT_Params.Arr_Reg_Key.Item("UPSName") & " (" & .Mfr & "/" & .Model & "/" & .Firmware & ")" & vbNewLine
136+
ToClipBoard = Arr_Reg_Key.Item("UPSName") & " (" & .Mfr & "/" & .Model & "/" & .Firmware & ")" & vbNewLine
138137
End With
139138
For Each LDatas In List_Var_Datas
140139
ToClipBoard &= LDatas.VarKey & " (" & LDatas.VarDesc & ") : " & LDatas.VarValue & vbNewLine

0 commit comments

Comments
 (0)