StealthRT
StealthRT

Reputation: 10542

If statement with 2 possible numbers

Hey all i am probably overthinking this but how can i check the textbox for either a 655 or 699 in the first 3 numbers in the textbox?

The current code i how now works but displays an error if (im guessing) it doesnt find the other number in the textbox as well:

 If Microsoft.VisualBasic.Mid(txtNumber.Text, 1, 3) <> 655 Or Microsoft.VisualBasic.Mid(txtNumber.Text, 1, 3) <> 699 Then
 'ERROR
 end if

What would i be doing incorrectly?

David

Upvotes: 0

Views: 316

Answers (3)

Nalaka526
Nalaka526

Reputation: 11464

try

    If Mid(txtNumber.Text, 1, 3) <> "655" And Mid(txtNumber.Text, 1, 3) <> "699" Then
        'Code
    End If

Upvotes: 0

Bryan Naegele
Bryan Naegele

Reputation: 660

First, you're going to want to use Left, not Mid if it's the first 3 characters.

Second, you're checking a string against an integer.

Third, you're checking if it's not those 3 characters when I'm guessing you want to check if they are equal, so you'll want to change that, as well.

Upvotes: 0

jmoreno
jmoreno

Reputation: 13561

Like so:

If Left(txtNumber.Text, 3) = "655" OrElse Left(txtNumber.Text, 3) = "699" Then 
   ' good?
End if 

Although it looks like you might want an error if it's not either one, in which case just wrap the two test above in paran's and put a Not before them.

Upvotes: 2

Related Questions