-
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:
For L = 0 To lstSong.Count - 1
txtlogin.Text = lstSong.List
thanks in advance
-
Re: For Statement & listbox help needed
Is this what you mean:
VB Code:
For L = 0 To lstSong.Count - 1
txtlogin.Text = txtlogin.Text & lstSong.List(L) & vbNewLine
Next L
-
Re: For Statement & listbox help needed
Quote:
Originally Posted by pnish
Is this what you mean:
VB Code:
For L = 0 To lstSong.Count - 1
txtlogin.Text = txtlogin.Text & lstSong.List(L) & vbNewLine
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.
-
Re: For Statement & listbox help needed
I'm not sure I completely understand, but what about this:
VB Code:
For L = 0 To lstSong.Count - 1
txtlogin.Text = lstSong.List(L)
'
' Code to process txtlogin.Text goes here
'
Next L ' Loop back for the next song
I assume you only want to process the entire list once. Is that right?
-
Re: For Statement & listbox help needed
Or.... to keep cycling through the list of songs 'forever'..
VB Code:
Dim lngNumSongs As Long
Dim lngCurrentSong As Long
lngNumSongs = lstSong.Count - 1
Do
txtlogin.Text = lstSong.List(lngCurrentSong)
'
' Code to process txtlogin.Text goes here
'
If lngCurrentSong >= lngNumSongs Then
lngCurrentSong = 0
Else
lngCurrentSong = lngCurrentSong + 1
End If
Loop
-
Re: For Statement & listbox help needed
Quote:
Originally Posted by pnish
Or.... to keep cycling through the list of songs 'forever'..
VB Code:
Dim lngNumSongs As Long
Dim lngCurrentSong As Long
lngNumSongs = lstSong.Count - 1
Do
txtlogin.Text = lstSong.List(lngCurrentSong)
'
' Code to process txtlogin.Text goes here
'
If lngCurrentSong >= lngNumSongs Then
lngCurrentSong = 0
Else
lngCurrentSong = lngCurrentSong + 1
End If
Loop
keep cycling forever =) i'll add the code to stop it. thanks
-
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?
-
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. :confused:
-
Re: For Statement & listbox help needed
VB Code:
'************* Login Names *
Dim lngNumLogin As Long
Dim lngCurrentLogin As Long
lngNumLogin = lstlogin.Count - 1
Do
txtlogin.Text = ""
txtlogin.Text = lstlogin.List(lngCurrentLogin)
'************* Login Names *
Dim nUrl As String
Dim B As Integer
Dim GetMoreNames As String
'****** Login Begin *
Dim strPostData As String
strPostData = "login_form_submit=1&alias=" + txtlogin.Text
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
Do
DoEvents
Loop Until Inet.StillExecuting = False
Inet.Execute "http://www.designkinky.com/devGOD/"
Do
DoEvents
Loop Until Inet.StillExecuting = False
'****** Login End *
For B = 0 To lstNames.ListCount - 1
txtSN.Text = lstNames.List(0)
lstNames.RemoveItem 0
If Err.Number = "35761" Then
Inet.Cancel
End If
nUrl = "http://updatelst.designkinky.com/Members/MyPage/songs_view.html?OPERATION=1&MEMBER="
Inet.OpenURL nUrl + txtSN.Text + "&POST.x=77&POST.y=9"
Do
DoEvents
If Err.Number = "35761" Or "35764" Then
Inet.Cancel
ElseIf Err.Number = 380 Then
Exit Sub
End If
Loop Until Not Inet.StillExecuting
If Err.Number = "35761" Then
Inet.Cancel
Exit Sub
End If
txtSN.Text = ""
If Err.Number = "35761" Then
Inet.Cancel
Exit Sub
ElseIf lstNames.ListCount = 0 Then
MsgBox "Done", vbSystemModal
Exit Sub
End If
'
' Code to process txtlogin.Text goes here
'
If lngCurrentLong >= lngNumLongs Then
lngCurrentLong = 0
Else
lngCurrentLong = lngCurrentLong + 1
End If
Loop Until lstNames.ListCount = 0
'********************************************
Next B
it's a little messy still working on it and the site pages to go with it
-
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
-
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]
-
Re: For Statement & listbox help needed
VB Code:
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
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:
If lngCurrentLong >= lngNumLongs Then
lngCurrentLong = 0
Else
lngCurrentLong = lngCurrentLong + 1
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....
-
Re: For Statement & listbox help needed
Quote:
Originally Posted by pnish
VB Code:
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
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:
If lngCurrentLong >= lngNumLongs Then
lngCurrentLong = 0
Else
lngCurrentLong = lngCurrentLong + 1
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?
-
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?
-
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
-
Re: For Statement & listbox help needed
Here's some simpler code based on what I understand:
VB Code:
Dim i As Integer
Dim j As Integer
'
' Process each login
'
For i = 0 To lstLogin.Count - 1
txtlogin.Text = lstLogin.List(i)
'
' Process each name for the current login
'
For j = 0 To lstNames.Count - 1
txtSN.Text = lstNames.List(j)
'
' Do whatever it is you do here
'
Next j
'
' Get the next login
'
Next i
Am I getting warm??
-
Re: For Statement & listbox help needed
that's it. a lot cleaner too =) my coding was really messy
-
Re: For Statement & listbox help needed
Why are you removing names from lstNames? Does this list get populated with different data for each login?
-
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
-
Re: For Statement & listbox help needed
OK. Great, I think we're there....
VB 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
How's that looking?
-
Re: For Statement & listbox help needed
-
Re: For Statement & listbox help needed
Quote:
Originally Posted by trisuglow
Try lstLogin.ListCount.
thanks
-
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
-
Re: For Statement & listbox help needed
Is this what you mean?
VB Code:
Dim i As Integer
'
' Process each login
'
For i = 0 To lstLogin.Count - 1
txtlogin.Text = lstLogin.List(i)
'
' Process one name for the current login
'
If lstNames.Count > 0 Then
txtSN.Text = lstNames.List(0)
lstNames.RemoveItem 0
'
' Do whatever it is you do here
'
End If
'
' Get the next login
'
Next i
-
Re: For Statement & listbox help needed
yes that looking like it, let me test
-
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
-
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:
Dim i As Integer
Do
'
' Process each login
'
For i = 0 To lstLogin.Count - 1
txtlogin.Text = lstLogin.List(i)
'
' Process one name for the current login
'
If lstNames.Count > 0 Then
txtSN.Text = lstNames.List(0)
lstNames.RemoveItem 0
'
' Do whatever it is you do here
'
End If
'
' Get the next login
'
Next i
Loop
-
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
-
Re: For Statement & listbox help needed
Good stuff. Glad I was able to help. :thumb:
Cheers