Solved

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

Posted on 2004-04-14
21
1,951 Views
Last Modified: 2012-06-21
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
Comment
Question by:bluedragon99
  • 14
  • 7
21 Comments
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828300
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828320
Never mind that does not work it sets true if Source Interface is found in the listview which means it displays all lines.
0
 
LVL 27

Accepted Solution

by:
Dabas earned 500 total points
ID: 10828372
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10828390
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10828400
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828421
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10828446
bluedragon99,
How and where did you declare SourceIntCol?

Dabas
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828455
on form load

Dim SourceIntCol As New Collection
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10828478
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828509
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:bluedragon99
ID: 10828552
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828571
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10828624
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828714
never been able to get the watches working it says

Watch :   : SetAlertsViewer : <Expression not defined in context> : Empty : Form1.Timer2_Timer
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828722
got the watch hang on..
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828776
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828811
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828841
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828877
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10828895
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10828939
Thanks Dabas!!! as usual you guys are great (thanks for the watch lesson :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 97
Delphi Mdi application Child forms get behind control 7 114
Replace a tag with sed 2 42
allStar challenge 1 41
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now