1.11M Members

If textbox1.text = one of more numbers

 
0
 

Hello programmers!

I want small help with code. I want something to happen when text in TextBox1 is A or B or C without writing same code 3 times. I don't know how to write it. I tried with it:

If TextBox1.Text = "A" or "B" or "C" Then
    'Event
End if

Thanks.

 
0
 

Try

If TextBox1.Text = "A" Or TextBox1.Text = "B" Or TextBox1.Text = "C" Then
    'Do Work
End If
 
2
 

There's no magic way to do it, but there's others ways like storing the values A,B,C in an array and loop for a match or using RegEx.

I'd use RegEx for a short code, something like this:

IF ( RegEx.Match(TextBox1.Text, "^[ABC]$").Success ) Then

End If

To use RegEx you need to import System.Text.RegularExpressions.

Question Answered as of 1 Year Ago by Begginnerdev and AleMonteiro
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article