Start New Discussion within our Software Development Community

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
End if


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.

This question has already been answered. Start a new discussion instead.