PDA

View Full Version : [VB6] Going through listbox items and looping my commands.



SmileYaDead
03-29-2012, 07:01 PM
I've been working on a program for a few days and I think I'm almost done, but since this is all my coding experience, I'm not good and rely mostly on tutorials. I just need some help getting my listbox items to be chosen automatically, at the moment I have to click on each one of the items and then click on the command button to get it to work. Should I use a different approach for the text list itself or..?

Also, looping is somehow a problem for me -.-

Thanks :)

Ryan~
03-29-2012, 07:04 PM
Idk about VB6, but it Java, you use a for each loop.

I'm sure someone will give you an exact answer, but look up for each loops.

Joshsadf
03-29-2012, 07:04 PM
Do until x = lstBox.listcount - 1
code here
x = x + 1
loop

Zachafer
03-29-2012, 07:13 PM
Do until x = lstBox.listcount - 1
code here
x = x + 1
loop

Better version:


x = 0
Do While x < lstBox.ListCount
'code here
x = x + 1
Loop

Or even a for loop:

For x = 0 To lstBox.ListCount - 1
'code here
Next x

In these cases, x is an index of the listbox.
You access the string in the listbox by lstBox.List(index)

SmileYaDead
03-29-2012, 07:21 PM
Thanks, I'll put this in tomorrow, need some sleep.

SmileYaDead
03-30-2012, 09:12 AM
How would these be in the VB 2010 version?

Zachafer
03-30-2012, 11:54 AM
How would these be in the VB 2010 version?

Close to the same:



Dim x = 0
Do While x < lstBox.Items.Count
'code here
x += 1
Loop

Or even a for loop:

For x As Integer = 0 To lstBox.Items.Count - 1
'code here
Next x

In these cases, x is an index of the listbox.
You access the string in the listbox by lstBox.Items(index)