I need some code that goes through each item in a listbox and executes a for next loop for each item
Printable View
I need some code that goes through each item in a listbox and executes a for next loop for each item
What? That makes no sense. Could you try that again?
-tg
K sorry
I have a listbox
I need to execute a For...Next Loop for each item in that listbox
Thx buts thats not it. I guess the correct term would be nested for...loop
so something like
for i as integer = 0 to listbox1.items.count -1
for a as integer = 0 to 12
msgbox(listbox1.items(i))
next
next
but the actual code will have more to it
ok this isnt working lol. I can't get the right words to explain it.
Let me try one more time:
What I have right now
A For...Next loop that is only targeting one item which is in a text box. I want to use a listbox instead of this textbox so the for...next loops can do a lot at the same time. So i need something that will go through the listbox and do this for...next loop for every item in it.
The for loop that manhit wrote will loop through every item in the list box. Looping through every item again while already looping through them is redundant.
You can do whatever you want to each individual list box item in this for loop.Code:Dim number As Integer = 1
For Each item In ListBox1.Items
item.Text = "Item " & number
number += 1
Next
If this is not what you need, you will have to explain EXACTLY what you want a little more clearly.
well here is the loop that doesnt work correctly
Code:
"this is the newly added for...next loop
For Each item In ListBox1.Items
'Sets server and port for smtp server
Dim Smtp As New System.Net.Mail.SmtpClient(SMTP1, Port)
'Message Details
Dim Message = New System.Net.Mail.MailMessage("[email protected]", item, subject, MSSG)
'Enables SS1 Encryption.
Smtp.EnableSsl = True
Try
'Sets username and password for account
Smtp.Credentials = New System.Net.NetworkCredential(Email, password)
Catch ex As Exception
MsgBox(ex.Message)
End Try
If Me.BackgroundWorker1.CancellationPending Then
Exit For
End If
Try
For n As Integer = 1 To Number
Smtp.Send(Message)
Me.BackgroundWorker1.ReportProgress(n, "Working...")
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next
Why do you want to send the same email to the same recipient n times? Are you trying to flood someone's mailbox?