Array looping

  • Thread starter Thread starter David C
  • Start date Start date
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
 
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, ";")
 
Back
Top