Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
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
 
Old November 30th, 2004, 07:51 AM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default 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

 
Old November 30th, 2004, 09:04 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 30th, 2004, 09:05 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 30th, 2004, 09:06 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 30th, 2004, 09:20 AM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default

You are a star ! Thank you.

B

 
Old November 30th, 2004, 09:21 AM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default

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

 
Old December 1st, 2004, 12:54 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old December 1st, 2004, 05:12 AM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default

Thanks for your help, much apprecoated !

B

 
Old December 2nd, 2004, 05:19 PM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default

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

 
Old December 3rd, 2004, 02:11 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with coding Gini Visual Studio 2008 2 March 6th, 2009 04:14 PM
Coding scrolling text with VS 2005/ASP.NET cJeffreywang ASP.NET 2.0 Professional 6 August 15th, 2007 07:28 AM
DTS scheduled jobs not finishing abob SQL Server DTS 0 July 13th, 2007 07:48 AM
Pixel lenght of a string bschleusner C# 2005 2 May 9th, 2007 07:35 AM
Need help finishing project mybudgethost PHP Databases 1 January 24th, 2005 04:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.