Results 1 to 13 of 13

Thread: Looping through 2 list boxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    24

    Looping through 2 list boxes

    kinda a continuation to my other thread, but i think it would just be better to start a new thread..

    Ok, i have 2 list boxes (list1, list 2), a web browser, and a start button.. I have it so the emails are in one list box, list1, and the passwords are in the 2nd listbox, list2. I highlight the first login in each box, and it sucessfully works, but i havent set it to go down the whole list of emails and passwords to do the same thing to each one to the end of each list box, i dont know how to do that.. i suppose it would be some kind of do/loop but i cant figure it out... There is also a load button, to load the txt file into the list boxes, but thats not really important because that already works.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Looping through 2 list boxes

    VB Code:
    1. Dim i As Long
    2.  
    3. For i = 0 To List1.ListCount - 1
    4.     'do whatcha gotta do through each loop here.
    5. Next

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Looping through 2 list boxes

    VB Code:
    1. For i = 0 To List1.ListCount - 1
    2.     'do whatcha gotta do through each loop here.
    3. Next [b]i[/b]

  4. #4
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Looping through 2 list boxes

    VB is a mixture of sequential and event driven.
    Actions etc can fire off events in VB code.
    However code that is being executed also has a desire to continue to the next line.
    (Until it reaches the exit point of it's procedure.)

    The answer probably depends on what needs to happen between lines ?

    You could set up a loop such as -
    VB Code:
    1. For i = 0 To lbo1.ListCount - 1
    2.   'code doing stuff for each line
    3.   ' using  lbo1(i).List(i)
    4. Next i
    That loop will process each line in sequence, until it runs out of data.

    However you may not want the 2nd line jumping in too soon ?
    So we may need to know a bit more about your 'needs'
    Rob C

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Looping through 2 list boxes

    Quote Originally Posted by |2eM!x
    VB Code:
    1. For i = 0 To List1.ListCount - 1
    2.     'do whatcha gotta do through each loop here.
    3. Next [b]i[/b]
    What is the difference between your post and mine?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    24

    Re: Looping through 2 list boxes

    do i need to have 2 for/next loops though? cause i have 2 list boxes that need to change at the same time, you know?

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Looping through 2 list boxes

    Quote Originally Posted by Josh2022
    do i need to have 2 for/next loops though? cause i have 2 list boxes that need to change at the same time, you know?
    Yes, you would and they should probably both be in the same code routine.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Looping through 2 list boxes

    If you have to do something to each item in both listboxes at the same time, then there's no reason for the second loop. The first one tells you the item number of both listboxes.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Looping through 2 list boxes

    Quote Originally Posted by Josh2022
    ...to do the same thing to each one to the end of each list box, i dont know how to do that.. i
    If you only need to do one thing to one of the listboxes, then dglienna is right, but based on the above comment, I thought you needed to do something to each listbox each time.

  10. #10
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Looping through 2 list boxes

    @ hack, i thought that every for loop had to have a corresponding next..

    anyway i guess its good coding to use it

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    24

    Re: Looping through 2 list boxes

    wow, you guys are so helpful! thankyou. ^_^

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Looping through 2 list boxes

    Quote Originally Posted by |2eM!x
    @ hack, i thought that every for loop had to have a corresponding next..

    anyway i guess its good coding to use it
    You do have to do a cooresponding Next, but you don't have list the looping variable. VB is smart enought to figure out what Next goes with what For, and if your code is properly indented, as it should always be, it is easy enough for anyone to figure out what does with what.
    Quote Originally Posted by josh2022
    wow, you guys are so helpful! thankyou
    So, how are you doing on coding this issue? Are you still running into some difficulties.

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Looping through 2 list boxes

    If it's usenames and passwords, there is a one to one correlation, so that's why I posted what I did.

Posting Permissions

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



Click Here to Expand Forum to Full Width