Results 1 to 2 of 2

Thread: Can't Fathom Out Why My Code Keeps Carrying On?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    29

    Can't Fathom Out Why My Code Keeps Carrying On?

    Hi guys, in my system i have two textobxes that are validated for a correct email format and if any of the emails are wrong a messagebox appears and notifies the user. The problem I'm having is that even when the user is notified the user presses 'OK' on the textbox but my system continues to read the other piece of code and further down my code, it saved the emails to the database, therefore it saved the email in the wrong format

    Here is my code where it format checks the email:
    Code:
    Dim FM As Boolean
            Dim FM2 As Boolean
    
            Try
                FM = Regex.IsMatch(txtEmail.Text, "\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)
            Catch ex As ArgumentException 'Syntax error in the regular expression
            End Try
            If Not FM Then
                MsgBox("Please Enter An Email Address In The Correct Format")
            Else
            End If
    
            Try
                FM2 = Regex.IsMatch(txtEmail2.Text, "\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)
            Catch ex As ArgumentException 'Syntax error in the regular expression
            End Try
            If Not FM2 Then
                MsgBox("Please Enter An Email Address In The Correct Format")
            Else
            End If
    Does anyone know how i can sort of "pause" my program and then allow the user to change the email before my code carries on.

    (the user presses a button which saved the emails)

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Can't Fathom Out Why My Code Keeps Carrying On?

    It is continuing with the other code because you aren't telling it not to.

    There are a variety of ways you could avoid running the rest of the code, including this:
    Code:
            If Not FM Then
                MsgBox("Please Enter An Email Address In The Correct Format")
                Exit Sub
            End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width