Listbox problem

atesh

Freshman
Joined
Aug 2, 2003
Messages
41
Location
Washington State, USA
Why do I get 'Specified argument was out of the range of valid values.'?

Visual Basic:
Dim z as integer = 0
        While srReader.Peek() > -1
            z += 1
            ListBox(1).Items.Item(z) = srReader.ReadLine()
            ListBox(1).Items.Add(ListBox(1).Items.Item(z))
        End While

Total it is supposed to load a little over 7000 lines into the listbox. I don't know if this has anything to do with it.
 
Its probably because you add one to z before doing anything to the listbox and it overflows by one. Try putting z =+ 1 after modifying the listbox.
 
Back
Top