Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21140

[RESOLVED] Need help with a Listbox.ListCount error

$
0
0
My goal is to get CheckList to exit the sub if there is nothing in List1, but otherwise to run the code that comes after the if/then statement. The following code exits the sub as though List1.ListCount were 0 or -1, when the value of List1.ListCount is obviously 200. Could someone please explain to me why this happens and how I could get it to work correctly?


Code:

Private Sub Form_Load()

    Dim i As Integer
   
    For i = 1 To 200
        List1.AddItem CStr(i)
    Next i
   
    MsgBox List1.ListCount
   
    CheckList

End Sub

Private Sub CheckList()

    If List1.ListCount = 0 Or -1 Then
        MsgBox "Exiting Sub"
        Exit Sub
    End If
   
    MsgBox List1.ListCount

End Sub


Viewing all articles
Browse latest Browse all 21140

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>