• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1976
  • Last Modified:

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


0
bluedragon99
Asked:
bluedragon99
  • 14
  • 7
1 Solution
 
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
0
 
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.
0
 
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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
0
 
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
0
 
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.
0
 
DabasCommented:
bluedragon99,
How and where did you declare SourceIntCol?

Dabas
0
 
bluedragon99Author Commented:
on form load

Dim SourceIntCol As New Collection
0
 
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
0
 
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.
0
 
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
0
 
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
0
 
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
0
 
bluedragon99Author Commented:
never been able to get the watches working it says

Watch :   : SetAlertsViewer : <Expression not defined in context> : Empty : Form1.Timer2_Timer
0
 
bluedragon99Author Commented:
got the watch hang on..
0
 
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

0
 
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
0
 
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 " "
0
 
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
0
 
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
0
 
bluedragon99Author Commented:
Thanks Dabas!!! as usual you guys are great (thanks for the watch lesson :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 14
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now