Results 1 to 29 of 29

Thread: For Statement & listbox help needed

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    For Statement & listbox help needed

    hi, heres what i'm trying to do need to be able to loop through lstSong and put each selection one at a time in txtlogin. once it gets to the bottom repeat. I also would like for it to show selection (.Selected)

    VB Code:
    1. For L = 0 To lstSong.Count - 1
    2. txtlogin.Text = lstSong.List

    thanks in advance

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Is this what you mean:
    VB Code:
    1. For L = 0 To lstSong.Count - 1
    2.     txtlogin.Text = txtlogin.Text & lstSong.List(L) & vbNewLine
    3. Next L
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    Quote Originally Posted by pnish
    Is this what you mean:
    VB Code:
    1. For L = 0 To lstSong.Count - 1
    2.     txtlogin.Text = txtlogin.Text & lstSong.List(L) & vbNewLine
    3. Next L

    not exactly if i'm reading that correctly. lstSong has a list of song titles in it. and i need to cycle through that list (lstSong) and put each name 1 at a time in the txtlogin.text box (more coding will process that). after txtlogin processes (txtlogin.text = "") the first song, it should loop back to the LstSong list and grab the next song. once at the bottom, restart at the top again

    your coding would just keep putting songs into the txtlogin box making another list right?

    my coding will go through the list once, i just need for it to keep cycling through once it gets to the bottom.

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    I'm not sure I completely understand, but what about this:
    VB Code:
    1. For L = 0 To lstSong.Count - 1
    2.     txtlogin.Text = lstSong.List(L)
    3.     '
    4.     '    Code to process txtlogin.Text goes here
    5.     '
    6. Next L    ' Loop back for the next song
    I assume you only want to process the entire list once. Is that right?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Or.... to keep cycling through the list of songs 'forever'..
    VB Code:
    1. Dim lngNumSongs As Long
    2. Dim lngCurrentSong As Long
    3. lngNumSongs = lstSong.Count - 1
    4.  
    5. Do
    6.     txtlogin.Text = lstSong.List(lngCurrentSong)
    7.     '
    8.     '    Code to process txtlogin.Text goes here
    9.     '
    10.     If lngCurrentSong >= lngNumSongs Then
    11.         lngCurrentSong = 0
    12.     Else
    13.         lngCurrentSong = lngCurrentSong + 1
    14.     End If
    15. Loop
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    Quote Originally Posted by pnish
    Or.... to keep cycling through the list of songs 'forever'..
    VB Code:
    1. Dim lngNumSongs As Long
    2. Dim lngCurrentSong As Long
    3. lngNumSongs = lstSong.Count - 1
    4.  
    5. Do
    6.     txtlogin.Text = lstSong.List(lngCurrentSong)
    7.     '
    8.     '    Code to process txtlogin.Text goes here
    9.     '
    10.     If lngCurrentSong >= lngNumSongs Then
    11.         lngCurrentSong = 0
    12.     Else
    13.         lngCurrentSong = lngCurrentSong + 1
    14.     End If
    15. Loop

    keep cycling forever =) i'll add the code to stop it. thanks

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    should i put my Next B statement after the Loop or before?

    Do ...coding grab song for txtlogin

    For Next ...coding process txtlogin
    viewing another second listbox

    Loop ...coding grab another LstSong

    Next B ... coding go back and cycle through a second listbox

    --------------
    i want two cycles to be going here. For Next listbox will process till it's completed at the End of the listbox. the Do statement listbox will continously cycle till i tell it to stop. actually i'm going to stop it with "Loop Until lstNames.ListCount = 0"

    I'm thinking i have to put the Next B inside the Loop that way, am i correct?
    Last edited by devGOD; Mar 9th, 2005 at 08:04 PM.

  8. #8
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Could you post some of your code or elaborate a bit more on exactly what it is you're trying to do. I'm just a little bit confused.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    VB Code:
    1. '************* Login Names *
    2.  
    3. Dim lngNumLogin As Long
    4. Dim lngCurrentLogin As Long
    5. lngNumLogin = lstlogin.Count - 1
    6.  
    7. Do
    8. txtlogin.Text = ""
    9.     txtlogin.Text = lstlogin.List(lngCurrentLogin)
    10.  
    11. '************* Login Names *
    12.  
    13. Dim nUrl As String
    14. Dim B As Integer
    15. Dim GetMoreNames As String
    16.  
    17. '****** Login Begin *
    18.  
    19.     Dim strPostData As String
    20.    
    21.     strPostData = "login_form_submit=1&alias=" + txtlogin.Text
    22.     Inet.Execute "http://www.designkinky.com/auth.html", "POST", strPostData, "Content-Type: application/x-www-form-urlencoded" & vbCrLf & "Referer: http://www.designkinky.com/Login/test.html" & vbCrLf
    23.    
    24. Do
    25. DoEvents
    26. Loop Until Inet.StillExecuting = False
    27.  
    28.     Inet.Execute "http://www.designkinky.com/devGOD/"
    29.  
    30. Do
    31. DoEvents
    32. Loop Until Inet.StillExecuting = False
    33.  
    34. '****** Login End *
    35.  
    36. For B = 0 To lstNames.ListCount - 1
    37.     txtSN.Text = lstNames.List(0)
    38.     lstNames.RemoveItem 0
    39.  
    40. If Err.Number = "35761" Then
    41.     Inet.Cancel
    42. End If
    43. nUrl = "http://updatelst.designkinky.com/Members/MyPage/songs_view.html?OPERATION=1&MEMBER="
    44. Inet.OpenURL nUrl + txtSN.Text + "&POST.x=77&POST.y=9"
    45. Do
    46. DoEvents
    47.  
    48.                     If Err.Number = "35761" Or "35764" Then
    49.                         Inet.Cancel
    50.                     ElseIf Err.Number = 380 Then
    51.                         Exit Sub
    52.                     End If
    53.  
    54. Loop Until Not Inet.StillExecuting
    55.  
    56. If Err.Number = "35761" Then
    57.     Inet.Cancel
    58.     Exit Sub
    59. End If
    60.  
    61. txtSN.Text = ""
    62.  
    63.     If Err.Number = "35761" Then
    64.         Inet.Cancel
    65.         Exit Sub
    66.     ElseIf lstNames.ListCount = 0 Then
    67.         MsgBox "Done", vbSystemModal
    68.         Exit Sub
    69.     End If
    70.    
    71.     '
    72.     '    Code to process txtlogin.Text goes here
    73.     '
    74.     If lngCurrentLong >= lngNumLongs Then
    75.         lngCurrentLong = 0
    76.     Else
    77.         lngCurrentLong = lngCurrentLong + 1
    78.     End If
    79. Loop Until lstNames.ListCount = 0
    80. '********************************************
    81.    
    82. Next B


    it's a little messy still working on it and the site pages to go with it

  10. #10
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    A couple of points:

    Do you have Option Explicit at the start of your form/module. The reason I ask is that I see several variables in your code which don't seem to be declared.

    If Err.Number = "35761" Or "35764" Then should be written as:
    If Err.Number = 35761 Or Err.Number = 35764 Then

    Your looping structures are incorrect and probably illegal.

    Tell me what you're trying to do step by step. Don't worry about the login stuff, just explain to me how you want the lists processed and in what order. Sorry if I seem a bit thick.

    Off to get something to eat now, back in a while.

    Cheers
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    here's a cleaner version of what i'm doing... i removed all the error checking. pretty much lstLogin is a loop while LstName supplies the songs.

    [Highlight=VB]
    Dim lngNumLogin As Long
    Dim lngCurrentLogin As Long
    lngNumLogin = lstlogin.Count - 1

    Do
    txtlogin.Text = ""
    txtlogin.Text = lstlogin.List(lngCurrentLogin)


    For B = 0 To lstNames.ListCount - 1
    txtSN.Text = lstNames.List(0)
    lstNames.RemoveItem 0

    URL processing code.........................

    txtSN.Text = ""

    '
    ' Code to process txtlogin.Text goes here
    '
    If lngCurrentLong >= lngNumLongs Then
    lngCurrentLong = 0
    Else
    lngCurrentLong = lngCurrentLong + 1
    End If

    Next B

    Loop Until lstNames.ListCount = 0
    [/vbode]
    Last edited by devGOD; Mar 9th, 2005 at 09:41 PM.

  12. #12
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    VB Code:
    1. Dim lngNumLogin As Long
    2.     Dim lngCurrentLogin As Long
    3.     lngNumLogin = lstlogin.Count - 1
    4.  
    5.     Do
    6.         txtlogin.Text = ""
    7.         txtlogin.Text = lstlogin.List(lngCurrentLogin)
    8.        
    9.         For B = 0 To lstNames.ListCount - 1
    10.             txtSN.Text = lstNames.List(0)
    11.             lstNames.RemoveItem 0
    12.            
    13.             'URL processing code.........................
    14.            
    15.             txtSN.Text = ""
    16.             '
    17.             ' Code to process txtlogin.Text goes here
    18.             '
    19.             If lngCurrentLong >= lngNumLongs Then
    20.                 lngCurrentLong = 0
    21.             Else
    22.                 lngCurrentLong = lngCurrentLong + 1
    23.             End If
    24.            
    25.         Next B
    26.        
    27.     Loop Until lstNames.ListCount = 0
    OK. I can see what's happening but I still don't understand what your problem is.
    The Do loop is redundant because you are removing each list item in the For/Next loop. When the For/Next is finished there will be no items left in the list so Loop Until lstNames.ListCount = 0 will be true the very first time it's executed.
    VB Code:
    1. If lngCurrentLong >= lngNumLongs Then
    2.                 lngCurrentLong = 0
    3.             Else
    4.                 lngCurrentLong = lngCurrentLong + 1
    5.             End If
    Does this code serve any purpose now? It doesn't appear to. At the top of your procedure you've defined lngNumLogin & lngCurrentLogin, but the code above references lngNumLongs & lngCurrentLong ?? Is that a typo? That's why I suggested you make sure you have Option Explicit declared at the start of your form/module. That will make sure that these sort of errors are picked up by the compiler.

    Back to you....
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    Quote Originally Posted by pnish
    VB Code:
    1. Dim lngNumLogin As Long
    2.     Dim lngCurrentLogin As Long
    3.     lngNumLogin = lstlogin.Count - 1
    4.  
    5.     Do
    6.         txtlogin.Text = ""
    7.         txtlogin.Text = lstlogin.List(lngCurrentLogin)
    8.        
    9.         For B = 0 To lstNames.ListCount - 1
    10.             txtSN.Text = lstNames.List(0)
    11.             lstNames.RemoveItem 0
    12.            
    13.             'URL processing code.........................
    14.            
    15.             txtSN.Text = ""
    16.             '
    17.             ' Code to process txtlogin.Text goes here
    18.             '
    19.             If lngCurrentLong >= lngNumLongs Then
    20.                 lngCurrentLong = 0
    21.             Else
    22.                 lngCurrentLong = lngCurrentLong + 1
    23.             End If
    24.            
    25.         Next B
    26.        
    27.     Loop Until lstNames.ListCount = 0
    OK. I can see what's happening but I still don't understand what your problem is.
    The Do loop is redundant because you are removing each list item in the For/Next loop. When the For/Next is finished there will be no items left in the list so Loop Until lstNames.ListCount = 0 will be true the very first time it's executed.
    VB Code:
    1. If lngCurrentLong >= lngNumLongs Then
    2.                 lngCurrentLong = 0
    3.             Else
    4.                 lngCurrentLong = lngCurrentLong + 1
    5.             End If
    Does this code serve any purpose now? It doesn't appear to. At the top of your procedure you've defined lngNumLogin & lngCurrentLogin, but the code above references lngNumLongs & lngCurrentLong ?? Is that a typo? That's why I suggested you make sure you have Option Explicit declared at the start of your form/module. That will make sure that these sort of errors are picked up by the compiler.

    Back to you....

    i don't want for the For/Next to remove all items from the list box in one pass. For each login one item should be processed in the for/next statement. The Do/Loop should just cycle the Logins while the For/Next grab a new name for each login it's presented..

    before i had the do/loop statement you gave me i just used 1 login. now i have multiples and i want to use a different name for each for/next name.

    does that sound better?

  14. #14
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Quote Originally Posted by devGOD
    does that sound better?
    Hmmm. I think so. Let me put it to you with some pseudo-code just to make sure I understand
    Code:
    Do for each Login
        For each item in lstNames
    
            do something with each lstNames item
    
        Next
        Remove this login from list
    Loop while lstLogin.Count > 0
    Have I got it?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    almost
    Code:
    Do for each Login
        For each item in lstNames
    
            do something with each lstNames item
            and REMOVE name for list
        Next
        LEAVE LOGIN on list <---- this is a list of logins that gets cycled
    Loop while lstLogin.Count > 0

  16. #16
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Here's some simpler code based on what I understand:
    VB Code:
    1. Dim i As Integer
    2.     Dim j As Integer
    3.     '
    4.     '   Process each login
    5.     '
    6.     For i = 0 To lstLogin.Count - 1
    7.         txtlogin.Text = lstLogin.List(i)
    8.         '
    9.         '   Process each name for the current login
    10.         '
    11.         For j = 0 To lstNames.Count - 1
    12.             txtSN.Text = lstNames.List(j)
    13.             '
    14.             '   Do whatever it is you do here
    15.             '
    16.         Next j
    17.         '
    18.         '   Get the next login
    19.         '
    20.     Next i
    Am I getting warm??
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    that's it. a lot cleaner too =) my coding was really messy

  18. #18
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Why are you removing names from lstNames? Does this list get populated with different data for each login?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    yes it get populated with a new list or updated list of song genres everytime i load the program

  20. #20
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    OK. Great, I think we're there....
    VB Code:
    1. Dim i As Integer
    2.     '
    3.     '   Process each login
    4.     '
    5.     For i = 0 To lstLogin.Count - 1
    6.         txtlogin.Text = lstLogin.List(i)
    7.         '
    8.         '   Process each name for the current login
    9.         '
    10.         Do While lstNames.Count > 0
    11.             txtSN.Text = lstNames.List(0)
    12.             lstNames.RemoveItem 0
    13.             '
    14.             '   Do whatever it is you do here
    15.             '
    16.         Loop
    17.         '
    18.         '   Get the next login
    19.         '
    20.     Next i
    How's that looking?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  21. #21
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: For Statement & listbox help needed

    Try lstLogin.ListCount.
    This world is not my home. I'm just passing through.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    Quote Originally Posted by trisuglow
    Try lstLogin.ListCount.

    thanks

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    the logins are not being processed correctly. here is what happening the For and Do statements are using 1 to process the entire Names list. once that is done then the logins start rotating to the txtlogin. its suppose to rotate the login for each name. every name that is process gets a new login.

    process one name for each login. is what i need, right now the code below is using 1 login to process all names.

    Code:
        Dim i As Integer
        '
        '   Process each login
        '
        For i = 0 To lstLogin.Count - 1
            txtlogin.Text = lstLogin.List(i)
            '
            '   Process each name for the current login
            '
            Do While lstNames.Count > 0
                txtSN.Text = lstNames.List(0)
                lstNames.RemoveItem 0
                '
                '   Do whatever it is you do here
                '
            Loop
            '
            '   Get the next login
            '
        Next i
    Last edited by devGOD; Mar 10th, 2005 at 04:19 PM.

  24. #24
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Is this what you mean?
    VB Code:
    1. Dim i As Integer
    2.     '
    3.     '   Process each login
    4.     '
    5.     For i = 0 To lstLogin.Count - 1
    6.         txtlogin.Text = lstLogin.List(i)
    7.         '
    8.         '   Process one name for the current login
    9.         '
    10.         If lstNames.Count > 0 Then
    11.             txtSN.Text = lstNames.List(0)
    12.             lstNames.RemoveItem 0
    13.             '
    14.             '   Do whatever it is you do here
    15.             '
    16.         End If
    17.         '
    18.         '   Get the next login
    19.         '
    20.     Next i
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    yes that looking like it, let me test

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    it's going down the login list once then stopping. do i need to put a Do Loop statement on the Login so it'll keep cycling the login names. there is like 30-40 logins and about 500 song names

  27. #27
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Yeah. Just wrap the whole thing in a Do/Loop. This will cycle through the logins forever so you need to add the code to break out of the loop when appropriate.
    VB Code:
    1. Dim i As Integer
    2.    
    3.     Do
    4.         '
    5.         '   Process each login
    6.         '
    7.         For i = 0 To lstLogin.Count - 1
    8.             txtlogin.Text = lstLogin.List(i)
    9.             '
    10.             '   Process one name for the current login
    11.             '
    12.             If lstNames.Count > 0 Then
    13.                 txtSN.Text = lstNames.List(0)
    14.                 lstNames.RemoveItem 0
    15.                 '
    16.                 '   Do whatever it is you do here
    17.                 '
    18.             End If
    19.             '
    20.             '   Get the next login
    21.             '
    22.         Next i
    23.     Loop
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: For Statement & listbox help needed

    thanks, everything is working =) i'm using Loop Until lstNames.ListCount = 0
    to stop the loop once all the songs are posted

  29. #29
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: For Statement & listbox help needed

    Good stuff. Glad I was able to help.

    Cheers
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

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