Results 1 to 7 of 7

Thread: [VB6] Going through listbox items and looping my commands.

Hybrid View

  1. #1
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m

    [VB6] Going through listbox items and looping my commands.

    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

  2. #2
    Ryan~'s Avatar
    Joined
    Jan 2012
    Posts
    123
    Userbars
    5
    Thanks
    1,380
    Thanked
    1,424/827
    DL/UL
    103/4
    Mentioned
    640 times
    Time Online
    15d 12h 13m
    Avg. Time Online
    5m
    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.

  3. #3

    Joined
    Dec 2011
    Posts
    262
    Thanks
    22
    Thanked
    106/68
    DL/UL
    22/0
    Mentioned
    74 times
    Time Online
    N/A
    Avg. Time Online
    N/A
    Do until x = lstBox.listcount - 1
    code here
    x = x + 1
    loop

  4. The Following User Says Thank You to Joshsadf For This Useful Post:

    SmileYaDead (03-29-2012)

  5. #4
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Quote Originally Posted by Josh View Post
    Do until x = lstBox.listcount - 1
    code here
    x = x + 1
    loop
    Better version:
    Code:
    x = 0
    Do While x < lstBox.ListCount
        'code here
        x = x + 1
    Loop
    Or even a for loop:
    Code:
    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)
    Last edited by Zachafer; 03-29-2012 at 07:16 PM.

  6. The Following User Says Thank You to Zachafer For This Useful Post:

    SmileYaDead (03-29-2012)

  7. #5
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m
    Thanks, I'll put this in tomorrow, need some sleep.

  8. #6
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m
    How would these be in the VB 2010 version?

  9. #7
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Quote Originally Posted by smileyadead View Post
    How would these be in the VB 2010 version?
    Close to the same:

    Code:
    Dim x = 0
    Do While x < lstBox.Items.Count
        'code here
        x += 1
    Loop
    Or even a for loop:
    Code:
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •