Array looping

D

David C

I am getting an exception error whenever the code below goes into the
For...Next loop. Can anyone spot what I am doing wrong? Also, the
txtEmailTo.Text has email addresses and if more than 1 they are separated by
a semicolon. Thanks.
David

Dim mm As New MailMessage()

'(2) Assign the MailMessage To and From properties
'Note that mm.To is a collection so that multiple people can be
emailed.
If InStr(txtEmailTo.Text, ";") > 0 Then
'Dim strEmailTo() = ""
Dim strTo As String
For Each strTo In Split(";", txtEmailTo.Text)
mm.To.Add(strTo)
Next
Else
mm.To.Add(txtEmailTo.Text)
End If
 
F

Family Tree Mike

David said:
I am getting an exception error whenever the code below goes into the
For...Next loop. Can anyone spot what I am doing wrong? Also, the
txtEmailTo.Text has email addresses and if more than 1 they are separated by
a semicolon. Thanks.
David

Dim mm As New MailMessage()

'(2) Assign the MailMessage To and From properties
'Note that mm.To is a collection so that multiple people can be
emailed.
If InStr(txtEmailTo.Text, ";") > 0 Then
'Dim strEmailTo() = ""
Dim strTo As String
For Each strTo In Split(";", txtEmailTo.Text)
mm.To.Add(strTo)
Next
Else
mm.To.Add(txtEmailTo.Text)
End If

You should be using:

for each strTo in Split(txtEmailTo.Text, ";")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top