Page 1 of 1

need help with listbox

Posted: Mon Nov 25, 2013 3:37 pm
by Dummy1912
hello,

who can help us with this weird small problem
it seems after been removed from listbox
and listbox will be empty it keeps going with checking

the point is when the listbox is empty it need to stop
because when everything has been deleted why do he keep checking it?

what did we forgot?
Code: Select all
            Dim file(ListBox2.Items.Count - 1) As String 
            For i = 0 To ListBox2.Items.Count - 1
                file(i) = ListBox2.Items(i).ToString()
            Next

            For x = 0 To file.Length - 1
                checkme()
                Me.Cursor = Cursors.Default
                If sended Then
                    ListBox2.Items.RemoveAt(0)
                    Application.DoEvents()
                End If

            Next
thank you.

Re: need help with listbox

Posted: Mon Nov 25, 2013 3:47 pm
by clanc789
What is 'checkme()' for function?

Re: need help with listbox

Posted: Mon Nov 25, 2013 4:16 pm
by Dummy1912
#clanc789
don't worry about the checkme() part
its the for x that has troubles :)

Re: need help with listbox

Posted: Mon Nov 25, 2013 5:27 pm
by XTechVB
well i forgot a lot about vb programming but it seems to me that this is the problem
Code: Select all
            For x = 0 To file.Length - 1
                checkme()
                Me.Cursor = Cursors.Default
                If sended Then
                    ListBox2.Items.RemoveAt(0)
                    Application.DoEvents()
                End If

            Next
Why don't you put that in a IF statement that checks if there are items in the listbox, if so runs the loop.

Re: need help with listbox

Posted: Mon Nov 25, 2013 6:23 pm
by Dummy1912
#XTechVB

i have that part already but doesn't do anything about it
it still continues.

Re: need help with listbox

Posted: Mon Nov 25, 2013 10:05 pm
by comathi
You remove the items from the ListBox, but you don't remove them from the array.

Could that be why it still checks even though the ListBox is empty?