-
Jul 17th, 2009, 08:51 PM
#1
Thread Starter
Lively Member
For Loop Problem
I need some code that goes through each item in a listbox and executes a for next loop for each item
-
Jul 17th, 2009, 09:00 PM
#2
Re: For Loop Problem
What? That makes no sense. Could you try that again?
-tg
-
Jul 17th, 2009, 09:03 PM
#3
Thread Starter
Lively Member
Re: For Loop Problem
K sorry
I have a listbox
I need to execute a For...Next Loop for each item in that listbox
-
Jul 17th, 2009, 09:07 PM
#4
Fanatic Member
Re: For Loop Problem
Originally Posted by Tddupre
K sorry
I have a listbox
I need to execute a For...Next Loop for each item in that listbox
Code:
for i as integer = 0 to listbox1.item.count -1
listbox1.items(i)= 'something
next
-
Jul 17th, 2009, 09:16 PM
#5
Thread Starter
Lively Member
Re: For Loop Problem
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
-
Jul 17th, 2009, 09:22 PM
#6
Fanatic Member
Re: For Loop Problem
Originally Posted by Tddupre
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
i write code manually so it is a bit uncorrect. other way :
Code:
For Each item In ListBox1.Items
MsgBox(item)
Next
-
Jul 17th, 2009, 09:40 PM
#7
Thread Starter
Lively Member
Re: For Loop Problem
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.
-
Jul 17th, 2009, 09:48 PM
#8
Addicted Member
Re: For Loop Problem
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.
Code:
Dim number As Integer = 1
For Each item In ListBox1.Items
item.Text = "Item " & number
number += 1
Next
You can do whatever you want to each individual list box item in this for loop.
If this is not what you need, you will have to explain EXACTLY what you want a little more clearly.
Last edited by Empyreal; Jul 17th, 2009 at 09:56 PM.
-
Jul 17th, 2009, 09:58 PM
#9
Thread Starter
Lively Member
Re: For Loop Problem
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("1234@mail.com", 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
-
Jul 17th, 2009, 10:12 PM
#10
Re: For Loop Problem
Why do you want to send the same email to the same recipient n times? Are you trying to flood someone's mailbox?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|