|
-
Feb 14th, 2000, 08:02 AM
#1
Thread Starter
Hyperactive Member
Does anyone have any suggestions on how to check a textbox to make sure it contains only numbers?
------------------
Ryan
[This message has been edited by Gimpster (edited 02-14-2000).]
-
Feb 14th, 2000, 08:12 AM
#2
Member
there is the IsNumeric function...
or
If str(val(text1.text)) = str(text1.text) then [it's only numbers...] but never tested it...
or just verify every keypress to the textbox and make sure it is a digit 0-9
------------------
Rapmaster
-
Feb 14th, 2000, 11:46 AM
#3
Lively Member
Gimpster,
the function "IsNumeric()" works, but recently i read about the "Like" function in a book which i found useful in my projects specially when i need string validations.
-
Feb 14th, 2000, 05:33 PM
#4
Frenzied Member
Personally I check that it's a number on the LostFocus event - you can catch the keypresses etc in the KeyDown, Change or Keypress event but you have to allow for the copy/pasting, delete key etc etc etc.
Textbox1_LostFocus
If Not IsNumeric(TextBox1.Text) Then
Msgbox "Must enter a number!"
TextBox1.SetFocus
End If
End Sub
This will prevent the user from moving onto the next control if they don't enter a number.
If you want to allow the user to leave the textbox blank you should insert
If TextBox1.Text="" Then Exit Sub
immediately below the TextBox1_LostFocus line (ie, before the IF)
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|