Click to See Complete Forum and Search --> : Determining if a Letter was pressed as opposed to a number
mcmcom
June 2nd, 2003, 10:29 AM
I have to create a validation handler for a project in school. As it stands now, I have a function that checks to make sure that a number is a positive number, but if I put in a letter I get a error
message that says that the string cannot be converted to double, can someone tell me what I can use to determine if a letter was entered so I can trap this error.
Thanks in advance,
Mike
Dozo_1st
June 2nd, 2003, 11:58 AM
Try dimming it as Object
validate oObject by using
oObject = "A"
do until Isnumeric(oObject) = true
oObject = Inputbox("etc")
loop
then validate for absolute #.. etc
This way you keep getting the inputbox until the input is numeric
Hope this helps... ;)
D.
digitalsunshine
June 3rd, 2003, 05:36 AM
hi,
try and paste this code in you textbox1_keypress event
Dim keyascii As Integer
keyascii = Asc(e.KeyChar)
Select Case keyascii
Case 49 To 57, 8, 13
Case 45
If InStr(TextBox1.Text, "-") <> 0 Then
keyascii = 0
End If
If TextBox1.SelectionStart <> 0 Then
keyascii = 0
End If
Case 46
If InStr(TextBox1.Text, ".") <> 0 Then
MsgBox("error")
keyascii = 0
End If
Case Else
keyascii = 0
End Select
If keyascii = 0 Then
e.Handled = True
Else
e.Handled = False
End If
it will take only numeric as input
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.