bluedragon99
asked on
Visual Basic IsNull problem, how to determine if var is null
Hello,
Here's the problem. if this (If Form2.SetAlertsViewer.List Items(H).L istSubItem s(1) = "Source Interface" Then) isn't true SourceIntCol collection never gets built and this (If SourceIntCol(H) = list(Counter) Then) compare sets true due to the fact that sourceintcol(h) is null. At least I think it is. Haven't had any luck with isnull. I need a way to make sure if it is null than it doesn't set If SourceIntCol(H) = list(Counter) Then equal to true. Help!
If A = 1 Then
FirstItem = list(Counter)
For H = 1 To Form2.SetAlertsViewer.List Items.Coun t
If Form2.SetAlertsViewer.List Items(H).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(H).L istSubItem s(3)
End If
If SourceIntCol(H) = list(Counter) Then
Set itmx = Alerter.AlerterStatus.List Items.Add( , , "")
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti on = Alerter.AlerterCount.Capti on + 1
Else
End If
Next
End If
Here's the problem. if this (If Form2.SetAlertsViewer.List
If A = 1 Then
FirstItem = list(Counter)
For H = 1 To Form2.SetAlertsViewer.List
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
End If
If SourceIntCol(H) = list(Counter) Then
Set itmx = Alerter.AlerterStatus.List
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti
Else
End If
Next
End If
ASKER
Never mind that does not work it sets true if Source Interface is found in the listview which means it displays all lines.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
bluedragon99,
What about this:
If A = 1 Then
FirstItem = list(Counter)
For Each li In Form2.SetAlertsViewer.List Items.Coun t
If li Is Nothing Then
'Do Nothing
Else
If Form2.SetAlertsViewer.List Items(H).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add(Form2.Set AlertsView er.ListIte ms(H).List SubItems(3 ))
If SourceIntCol(H) = list(Counter) Then
itmx = Alerter.AlerterStatus.List Items.Add( , , "")
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti on = Alerter.AlerterCount.Capti on + 1
Else
End If
End If
End If
Next
End If
Dabas
What about this:
If A = 1 Then
FirstItem = list(Counter)
For Each li In Form2.SetAlertsViewer.List
If li Is Nothing Then
'Do Nothing
Else
If Form2.SetAlertsViewer.List
SourceIntCol.Add(Form2.Set
If SourceIntCol(H) = list(Counter) Then
itmx = Alerter.AlerterStatus.List
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti
Else
End If
End If
End If
Next
End If
Dabas
Oops
Rewrite:
For Each li In Form2.SetAlertsViewer.List Items.Coun t
If li Is Nothing Then
'Do Nothing
Else
If li.SubItems(1) = "Source Interface" Then
SourceIntCol.Add(li.SubIte ms(3))
etc
Dabas
Rewrite:
For Each li In Form2.SetAlertsViewer.List
If li Is Nothing Then
'Do Nothing
Else
If li.SubItems(1) = "Source Interface" Then
SourceIntCol.Add(li.SubIte
etc
Dabas
ASKER
No luck and when it writes to the alert window the fields are completly blank. I really think SourceIntCol(H) is null and the compare is failing somehow. I just don't get it.
bluedragon99,
How and where did you declare SourceIntCol?
Dabas
How and where did you declare SourceIntCol?
Dabas
ASKER
on form load
Dim SourceIntCol As New Collection
Dim SourceIntCol As New Collection
bluedragon99,
You are adding the contents of SubItem(3) to the collection.
Is nothing being added at all, or sometimes yes, sometimes no?
What is SubItems(3) holding?
Dabas
You are adding the contents of SubItem(3) to the collection.
Is nothing being added at all, or sometimes yes, sometimes no?
What is SubItems(3) holding?
Dabas
ASKER
This program monitors flows on cisco routers. users can set alerts like Source Interface = AT1/0.100
SubItem(1) = "Source Interface"
SubItem(2) = "="
SubItem(3) = "AT1/0.100"
This function I am writing searches the list box for a set alert of source interface and if it finds it compares what it found from the router list(Counter) and the Subitems(3) var. If the are equal it prints it to the alert window. Basicly whats happing is the if's are setting true when the should be false. if list(counter) and subitems(3) don't equal, possibly because of it reading the list in (subitem 3 or subitem 1) as null thus screwing up the if statements with nulls... hope this helps.
SubItem(1) = "Source Interface"
SubItem(2) = "="
SubItem(3) = "AT1/0.100"
This function I am writing searches the list box for a set alert of source interface and if it finds it compares what it found from the router list(Counter) and the Subitems(3) var. If the are equal it prints it to the alert window. Basicly whats happing is the if's are setting true when the should be false. if list(counter) and subitems(3) don't equal, possibly because of it reading the list in (subitem 3 or subitem 1) as null thus screwing up the if statements with nulls... hope this helps.
ASKER
Simplified it. This msgbox "MsgBox SourceIntCol(H)" never comes up at all even when source interface is in the 1,1 position
How do I check if it's null all the ways I know are not working..
If A = 1 Then
FirstItem = list(Counter)
For H = 1 To Form2.SetAlertsViewer.List Items.Coun t
MsgBox "list count is " & Form2.SetAlertsViewer.List Items.Coun t
If Form2.SetAlertsViewer.List Items(H).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(H).L istSubItem s(3)
MsgBox SourceIntCol(H)
End If
If SourceIntCol(H) <> list(Counter) Then
MsgBox "the two vars are NOT equal"
End If
Next
End If
How do I check if it's null all the ways I know are not working..
If A = 1 Then
FirstItem = list(Counter)
For H = 1 To Form2.SetAlertsViewer.List
MsgBox "list count is " & Form2.SetAlertsViewer.List
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
MsgBox SourceIntCol(H)
End If
If SourceIntCol(H) <> list(Counter) Then
MsgBox "the two vars are NOT equal"
End If
Next
End If
ASKER
and this one comes up whether I do <> or =.......?!??!
If SourceIntCol(H) <> list(Counter) Then
MsgBox "the two vars are NOT equal"
End If
If SourceIntCol(H) <> list(Counter) Then
MsgBox "the two vars are NOT equal"
End If
bluedragon99,
Set a breakpoint on the IF .... = "Source Interface" line by placing the cursor on it and pressing F9
Run the program and when it stops at the breakpoint:
Highlight Form2.SetAlertsViewer.List Items(H).L istSubItem s(1), right click and Add Watch
I have the feeling the contents are not exactly "Source Interface"
Dabas
Set a breakpoint on the IF .... = "Source Interface" line by placing the cursor on it and pressing F9
Run the program and when it stops at the breakpoint:
Highlight Form2.SetAlertsViewer.List
I have the feeling the contents are not exactly "Source Interface"
Dabas
ASKER
never been able to get the watches working it says
Watch : : SetAlertsViewer : <Expression not defined in context> : Empty : Form1.Timer2_Timer
Watch : : SetAlertsViewer : <Expression not defined in context> : Empty : Form1.Timer2_Timer
ASKER
got the watch hang on..
ASKER
Ok set three watches. It appears that the problem is SourceIntCol(P) is not defined because of this if failing:
If Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(P).L istSubItem s(3)
End If
sooo...this SourceIntCol(P) doesn't exist. How do I get around this?
Change: + : Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) : "Source IP" : Object/IListSubItem : Form1.Timer2_Timer
Watch : : List(Counter) : "************" : Variant/String : Form1.Timer2_Timer
Watch : : SourceIntCol(P) : <Invalid procedure call or argument> : Variant/Integer : Form1.Timer2_Timer
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
End If
sooo...this SourceIntCol(P) doesn't exist. How do I get around this?
Change: + : Form2.SetAlertsViewer.List
Watch : : List(Counter) : "************" : Variant/String : Form1.Timer2_Timer
Watch : : SourceIntCol(P) : <Invalid procedure call or argument> : Variant/Integer : Form1.Timer2_Timer
ASKER
If I do this it fixes the problem completly but this won't work because it only compares the alert values no the types...if someone set a source ip alert and this finds a destination ip that matches it could alert
' If Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(P).L istSubItem s(3)
' End If
' If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
' End If
ASKER
This also works but will it cause problems with other alerts? If it doesn't get defined by finding source int it defines it as a space and then it fails the next compare (what the router says and what val the alert is set for)
If Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(P).L istSubItem s(3)
End If
SourceIntCol.Add " "
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
End If
SourceIntCol.Add " "
ASKER
This is my final code which seems to work great. This seemed to be the key:
If Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(P).L istSubItem s(3)
End If
SourceIntCol.Add " "
Any better ideas??
If A = 1 Then
Dim SourceIntCol As New Collection
FirstItem = list(Counter)
For P = 1 To Form2.SetAlertsViewer.List Items.Coun t
If Form2.SetAlertsViewer.List Items(P).L istSubItem s(1) = "Source Interface" Then
SourceIntCol.Add Form2.SetAlertsViewer.List Items(P).L istSubItem s(3)
End If
SourceIntCol.Add " "
If SourceIntCol(P) = list(Counter) Then
Set itmx = Alerter.AlerterStatus.List Items.Add( , , "")
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti on = Alerter.AlerterCount.Capti on + 1
Else
End If
Next
End If
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
End If
SourceIntCol.Add " "
Any better ideas??
If A = 1 Then
Dim SourceIntCol As New Collection
FirstItem = list(Counter)
For P = 1 To Form2.SetAlertsViewer.List
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
End If
SourceIntCol.Add " "
If SourceIntCol(P) = list(Counter) Then
Set itmx = Alerter.AlerterStatus.List
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti
Else
End If
Next
End If
bluedragon99,
> This is my final code which seems to work great.
Glad it is working.
An allocation of the points will be greatly appreciated!
Dabas
> This is my final code which seems to work great.
Glad it is working.
An allocation of the points will be greatly appreciated!
Dabas
ASKER
Thanks Dabas!!! as usual you guys are great (thanks for the watch lesson :)
ASKER
If A = 1 Then
FirstItem = list(Counter)
For H = 1 To Form2.SetAlertsViewer.List
If Form2.SetAlertsViewer.List
SourceIntCol.Add Form2.SetAlertsViewer.List
Else
GoTo NotThisone:
End If
If SourceIntCol(H) = list(Counter) Then
Set itmx = Alerter.AlerterStatus.List
itmx.SubItems(1) = "Source Interface"
If DecimalPorts.Checked = True Then
SixthField = CLng("&H" & (SixthField))
SeventhField = CLng("&H" & (SeventhField))
End If
itmx.SubItems(2) = FirstField
itmx.SubItems(3) = SecondField
itmx.SubItems(4) = ThirdField
itmx.SubItems(5) = FourthField
If ProtoDec.Checked = True Then
Call ProtoConvert(FifthItem)
FifthField = FifthItem
End If
itmx.SubItems(6) = FifthField
itmx.SubItems(7) = SixthField
itmx.SubItems(8) = SeventhField
itmx.SubItems(9) = EighthField
Alerter.AlerterCount.Capti
Else
End If
NotThisone:
Next
End If