Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27373

VS 2013 For each loop with every item in list box?

$
0
0
Hey guys,

So I have a simple listbox with an add and remove button. After the listbox is populated(maximum of 6 items), I need to do something with each item, but can't seem to get there.

Code:

        For i As Integer = 0 To lstListBox.Items.Count - 1
            strVar1 = CStr(lstListBox.Items(0))
            strVar2 = CStr(lstListBox.Items(1))
            strVar3 = CStr(lstListBox.Items(2))
            strVar4 = CStr(lstListBox.Items(3))
            strVar5 = CStr(lstListBox.Items(4))
            strVar6 = CStr(lstListBox.Items(5))
        Next

This seems to work pretty well, but if the user has only entered 3 listbox items(which needs to be a possibility) it throws an ArgumentOutOfRange exception.
Need a fix around for this:confused:

Viewing all articles
Browse latest Browse all 27373

Trending Articles



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