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



If TextBox1.Text = "A" Or TextBox1.Text = "B" Or TextBox1.Text = "C" Then
    'Do Work
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.

commented: Nice +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.