We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,389 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

If textbox1.text = one of more numbers

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.

3
Contributors
2
Replies
1 Hour
Discussion Span
5 Months Ago
Last Updated
4
Views
Question
Answered
LD Company
Light Poster
30 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Try

If TextBox1.Text = "A" Or TextBox1.Text = "B" Or TextBox1.Text = "C" Then
    'Do Work
End If
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8

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.

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23
Question Answered as of 5 Months Ago by Begginnerdev and AleMonteiro

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0674 seconds using 2.67MB