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

Making the rules of a text box

Hello guys,

I've newly joined this forum since I want to enhance my knowledge in Programming specially in Visual Basic.

So for the important part, right now I'm planning on creating a word detector somehow and there are specific rules I was to set in the textbox in relation with the button.
Let's say I wanna set an IF Statement for the text to have 32 characters and letters "abcdefg" and numbers "12345" so that it'll execute a message box when I press the button.

Here's a code example of what I'm saying

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text.Length.Equals(32) Then
    MessageBox.Show("You word has 32 Characters")
    End If
    End Sub

As you can see, I've set a rule that a message box will pop up if the word has 32 characters.
But I need to set another rule at the same time in which the word will have only letters "abcdefg" and numbers "12345"

Any ideas?
Help would be appreciated
Thanks in advance
zerofreak@live.com

3
Contributors
5
Replies
21 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
Question
Answered
zerofreak
Newbie Poster
8 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I suggest to trap it when user input the characters.
So, users can only input the specific characters.
Example : (This text box only accept numbers input only)

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
    If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
        e.Handled = True
    End 
    If Asc(e.KeyChar) = 8 Then
        e.Handled = False
    End If
End Sub
Jx_Man
Senior Poster
3,527 posts since Nov 2007
Reputation Points: 1,482
Solved Threads: 516
Skill Endorsements: 64

Thanks mate
I'm gonna give it a try now

zerofreak
Newbie Poster
8 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It worked pretty well
However, I'm still stuck at something

Lets say I want a message box to appear when a specific text like $1$ and other text like abcdefg and the limit of the characters is 32

Is there any specific code for that?

zerofreak
Newbie Poster
8 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
If TextBox1.Text.Contains("$1$") and TextBox1.Text.Contains("abcdefg") and Len(TextBox1.Text) = 32 then
    MsgBox("hit")
End If
Reverend Jim
Carpe per diem
Moderator
3,596 posts since Aug 2010
Reputation Points: 561
Solved Threads: 446
Skill Endorsements: 32
If TextBox1.Text.Contains("$1$") and TextBox1.Text.Contains("abcdefg") and Len(TextBox1.Text) = 32 then
    MsgBox("hit")
End If

Thanks a lot for the help
This one helped me a lot
Problem solved

zerofreak
Newbie Poster
8 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Jx_Man and Reverend Jim

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

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0738 seconds using 2.69MB