Array looping

Discussion in 'ASP .Net' started by David C, Jul 19, 2009.

  1. David C

    David C Guest

    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 C, Jul 19, 2009
    #1
    1. Advertising

  2. David C wrote:
    > 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, ";")

    --
    Mike
    Family Tree Mike, Jul 19, 2009
    #2
    1. Advertising

  3. David C

    David C Guest

    Thanks Mike. Simple mistake.
    David
    "Family Tree Mike" <> wrote in message
    news:%...
    > David C wrote:
    >> 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, ";")
    >
    > --
    > Mike
    David C, Jul 20, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curts
    Replies:
    1
    Views:
    323
    Lee Fesperman
    Aug 21, 2003
  2. Psybar Phreak
    Replies:
    1
    Views:
    565
    Eric Sosman
    Oct 6, 2003
  3. Martin
    Replies:
    9
    Views:
    296
    Robert Kern
    Jul 27, 2009
  4. Replies:
    2
    Views:
    99
  5. Replies:
    5
    Views:
    273
Loading...

Share This Page