 |
| VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 30th, 2004, 07:51 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Help with finishing coding on text lenght...
Hi there,
Could anyone help me with a bit of coding, I'm stuck ??
I have 4 textboxes that need to be able to only accept numerical numbers between 1 and 6 digits in length.I have managed the first part but dont know what coding to put down that will ensure that 1-6 digits are entered.I know that I will have to display an error message if more than 6 digits are entered but what code will bring that message up?
Any help would be greatly appreciated.
Thanking you
B
|
|

November 30th, 2004, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If IsNumeric(e.KeyChar) = False or (txtNumeric.Length > 6) Then
e.Handled = True
End If
The above three lines of code will allow only the digits and only 6 digits.
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|

November 30th, 2004, 09:05 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Write the above code in the Text_changed event
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|

November 30th, 2004, 09:06 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am really sorry that should be on the TextBox1_KeyPress event.
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|

November 30th, 2004, 09:20 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are a star ! Thank you.
B
|
|

November 30th, 2004, 09:21 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could I ask you one more question?
I can only get 1 textbox to acknowledge this, how would I make every textbox respond to my code?
Thanks again
B
|
|

December 1st, 2004, 12:54 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can attach the four text boxes to the same event if you don't have any other extra processing specific to the text Box.
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|

December 1st, 2004, 05:12 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your help, much apprecoated !
B
|
|

December 2nd, 2004, 05:19 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok so I tried what you said and still no luck, would somebody mind having a look at this code and helping me finish it?
This is what I have so far, it makes sure that numbers are inserted and comes up with error message if numbers not numerical.
f (Txtrefnumber.MaxLength > 6) Then
MessageBox.Show("You must enter a six digit reference number")
Else
Txtrefnumber.Text = ""
End If
If IsNumeric(Txtrefnumber.Text) = False Then
MessageBox.Show("You must enter a numeric value")
End If
If Txtrefnumber.CanFocus Then
Txtrefnumber.Focus()
Txtrefnumber.Text = ""
End If
Now I need the code tob also only accept a reference number of six digits long, no more no less.....Can anyone please help me?
Regards
B
|
|

December 3rd, 2004, 02:11 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If IsNumeric(e.KeyChar) = False or (txtNumeric.Length > 6) Then
e.Handled = True
End If
You add the above lines in the Keypress event, this will make sure that the textbox is accepting only the numeric values and only max of 6 digits.
At the point where you are validating the reference number (i.e. textbox value)
check whether it is 5 digits and then if not say a error msgbox, also set focus to the textbox like below
if (txtBox1.text.length <> 5) then
MsgBox(" Enter a valid 5 digit reference number ")
txtBox1.Focus()
End if
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|
 |