Visual Basic IsNull problem, how to determine if var is null

Hello,

Here's the problem. if this (If Form2.SetAlertsViewer.ListItems(H).ListSubItems(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.ListItems.Count
       
        If Form2.SetAlertsViewer.ListItems(H).ListSubItems(1) = "Source Interface" Then
              SourceIntCol.Add Form2.SetAlertsViewer.ListItems(H).ListSubItems(3)
        End If
       
       
   

        If SourceIntCol(H) = list(Counter) Then
       
            Set itmx = Alerter.AlerterStatus.ListItems.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.Caption = Alerter.AlerterCount.Caption + 1
    Else
    End If

Next
End If


LVL 1
bluedragon99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bluedragon99Author Commented:
This works but it's ghetto, any better ways other than goto??

If A = 1 Then
    FirstItem = list(Counter)

    For H = 1 To Form2.SetAlertsViewer.ListItems.Count
       
        If Form2.SetAlertsViewer.ListItems(H).ListSubItems(1) = "Source Interface" Then
              SourceIntCol.Add Form2.SetAlertsViewer.ListItems(H).ListSubItems(3)
        Else
            GoTo NotThisone:
        End If
       
       
   

        If SourceIntCol(H) = list(Counter) Then
       
            Set itmx = Alerter.AlerterStatus.ListItems.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.Caption = Alerter.AlerterCount.Caption + 1
    Else
    End If
NotThisone:
Next
End If
bluedragon99Author Commented:
Never mind that does not work it sets true if Source Interface is found in the listview which means it displays all lines.
DabasCommented:
Hi bluedragon99,
       If A = 1 Then
            FirstItem = list(Counter)

            For H = 1 To Form2.SetAlertsViewer.ListItems.Count

                If Form2.SetAlertsViewer.ListItems(H).ListSubItems(1) = "Source Interface" Then
                    SourceIntCol.Add(Form2.SetAlertsViewer.ListItems(H).ListSubItems(3))




                    If SourceIntCol(H) = list(Counter) Then

                        itmx = Alerter.AlerterStatus.ListItems.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.Caption = Alerter.AlerterCount.Caption + 1
                    Else
                    End If
                End If
'Not this one will come to here anyhow
            Next
        End If
 
Dabas

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

DabasCommented:
bluedragon99,
What about this:

        If A = 1 Then
            FirstItem = list(Counter)

            For Each li In Form2.SetAlertsViewer.ListItems.Count

                If li Is Nothing Then
                    'Do Nothing
                Else
                    If Form2.SetAlertsViewer.ListItems(H).ListSubItems(1) = "Source Interface" Then
                        SourceIntCol.Add(Form2.SetAlertsViewer.ListItems(H).ListSubItems(3))




                        If SourceIntCol(H) = list(Counter) Then

                            itmx = Alerter.AlerterStatus.ListItems.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.Caption = Alerter.AlerterCount.Caption + 1
                        Else
                        End If
                    End If
                End If
            Next
        End If

Dabas
DabasCommented:
Oops

Rewrite:


            For Each li In Form2.SetAlertsViewer.ListItems.Count

                If li Is Nothing Then
                    'Do Nothing
                Else
                    If li.SubItems(1) = "Source Interface" Then
                        SourceIntCol.Add(li.SubItems(3))
etc




Dabas
bluedragon99Author Commented:
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.
DabasCommented:
bluedragon99,
How and where did you declare SourceIntCol?

Dabas
bluedragon99Author Commented:
on form load

Dim SourceIntCol As New Collection
DabasCommented:
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
bluedragon99Author Commented:
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.
bluedragon99Author Commented:
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.ListItems.Count

          MsgBox "list count is " & Form2.SetAlertsViewer.ListItems.Count
       
       
        If Form2.SetAlertsViewer.ListItems(H).ListSubItems(1) = "Source Interface" Then
            SourceIntCol.Add Form2.SetAlertsViewer.ListItems(H).ListSubItems(3)
            MsgBox SourceIntCol(H)
        End If
       
       
        If SourceIntCol(H) <> list(Counter) Then
            MsgBox "the two vars are NOT equal"
        End If


Next
End If
bluedragon99Author Commented:
and this one comes up whether I do <> or =.......?!??!

 If SourceIntCol(H) <> list(Counter) Then
            MsgBox "the two vars are NOT equal"
        End If
DabasCommented:
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.ListItems(H).ListSubItems(1), right click  and Add Watch
I have the feeling the contents are not exactly "Source Interface"

Dabas
bluedragon99Author Commented:
never been able to get the watches working it says

Watch :   : SetAlertsViewer : <Expression not defined in context> : Empty : Form1.Timer2_Timer
bluedragon99Author Commented:
got the watch hang on..
bluedragon99Author Commented:
Ok set three watches.  It appears that the problem is SourceIntCol(P) is not defined because of this if failing:

If Form2.SetAlertsViewer.ListItems(P).ListSubItems(1) = "Source Interface" Then
        SourceIntCol.Add Form2.SetAlertsViewer.ListItems(P).ListSubItems(3)
End If

sooo...this SourceIntCol(P) doesn't exist.  How do I get around this?


Change: + : Form2.SetAlertsViewer.ListItems(P).ListSubItems(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

bluedragon99Author Commented:
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.ListItems(P).ListSubItems(1) = "Source Interface" Then
        SourceIntCol.Add Form2.SetAlertsViewer.ListItems(P).ListSubItems(3)
'   End If
bluedragon99Author Commented:
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.ListItems(P).ListSubItems(1) = "Source Interface" Then
        SourceIntCol.Add Form2.SetAlertsViewer.ListItems(P).ListSubItems(3)
   End If
        SourceIntCol.Add " "
bluedragon99Author Commented:
This is my final code which seems to work great.  This seemed to be the key:  

   If Form2.SetAlertsViewer.ListItems(P).ListSubItems(1) = "Source Interface" Then
        SourceIntCol.Add Form2.SetAlertsViewer.ListItems(P).ListSubItems(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.ListItems.Count

   If Form2.SetAlertsViewer.ListItems(P).ListSubItems(1) = "Source Interface" Then
        SourceIntCol.Add Form2.SetAlertsViewer.ListItems(P).ListSubItems(3)
   End If
        SourceIntCol.Add " "


If SourceIntCol(P) = list(Counter) Then
        Set itmx = Alerter.AlerterStatus.ListItems.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.Caption = Alerter.AlerterCount.Caption + 1
        Else
        End If



Next
End If
DabasCommented:
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
bluedragon99Author Commented:
Thanks Dabas!!! as usual you guys are great (thanks for the watch lesson :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.