Connecting Tech Pros Worldwide Forums | Help | Site Map

Control format of input

Newbie
 
Join Date: Jul 2007
Posts: 4
#1: Jul 31 '07
hey I am using the VB6.0 and I creating an order entry form interface. So in my order form it has an Quantity, Rate and Description Column so in quantity and rate column I dont want to enter any letters on it only a number so I want to know what code do I have to make so when someone want to enter a letters a messagebox will appear and say "Invalid Number"....please can you help me out....

pureenhanoi's Avatar
Familiar Sight
 
Join Date: Mar 2007
Location: VietNam
Posts: 175
#2: Jul 31 '07

re: Control format of input


Quote:

Originally Posted by lita

hey I am using the VB6.0 and I creating an order entry form interface. So in my order form it has an Quantity, Rate and Description Column so in quantity and rate column I dont want to enter any letters on it only a number so I want to know what code do I have to make so when someone want to enter a letters a messagebox will appear and say "Invalid Number"....pliz can you help me out....

Enter code into KeyPress Event
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(KeyAscii As Integer)
  2. If (KeyAscii < Asc("0") Or KeyAscii>Asc("9")) And Not KeyAscii=8 Then
  3.   KeyAscii = 0
  4.   Msgbox "Invalid Number"
  5. End If
  6. End Sub
  7.  
You need KeyAscii = 8 to enable BackSpace key
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#3: Jul 31 '07

re: Control format of input


What type of control are you using to enter the information? If it's a text box, you might instead try looking into the Masked Edit Control - it allows you to control the format of the input.

Oh, and by the way. Please try to use a title which reflects what is in your message, not just "help".
Newbie
 
Join Date: Jul 2007
Posts: 4
#4: Aug 7 '07

re: Control format of input


hey thnx 4 help 'n' sori abt that m jst little confuse.....okkkk...


Quote:

Originally Posted by Killer42

What type of control are you using to enter the information? If it's a text box, you might instead try looking into the Masked Edit Control - it allows you to control the format of the input.

Oh, and by the way. Please try to use a title which reflects what is in your message, not just "help".

Newbie
 
Join Date: Jul 2007
Posts: 4
#5: Aug 7 '07

re: Control format of input


hey thnx.....and m trying that coding it's work...see ya...


Quote:

Originally Posted by pureenhanoi

Enter code into KeyPress Event

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(KeyAscii As Integer)
  2. If (KeyAscii < Asc("0") Or KeyAscii>Asc("9")) And Not KeyAscii=8 Then
  3.   KeyAscii = 0
  4.   Msgbox "Invalid Number"
  5. End If
  6. End Sub
  7.  
You need KeyAscii = 8 to enable BackSpace key

Reply


Similar Visual Basic 4 / 5 / 6 bytes