Simple Is numeric statement :mad:
Hi guys,
Want 2 know some simple code for stopping alphabetical data being entered into a textbox. And allowing numerical data :thumb:
Got any ideas, my last try was:
VB Code:
Private Sub txtContactno_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then ' For some reason this doesn't work
KeyAscii = 0
End If
End Sub
Re: Simple Is numeric statement :mad:
You need to pass two parmameters first one is "keyascii" and second is textbox name
VB Code:
Public Sub OnlyNumeric(ByRef KeyAscii As Integer, Txt As TextBox)
Select Case KeyAscii
Case 48 To 57
IntPosition = InStr(1, Txt.Text, ".")
If IntPosition > 0 Then
If Len(Txt.Text) - InStr(1, Txt, ".") = 4 Then
KeyAscii = 0
Else
KeyAscii = KeyAscii
End If
End If
Case 8
Case 46
If InStr(1, Txt, ".") Then
KeyAscii = 0
Else
KeyAscii = KeyAscii
End If
Case 45
If InStr(1, Txt.Text, "-") Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub
Re: Simple Is numeric statement :mad:
Quote:
Originally Posted by ThePCMan
Hi guys,
Want 2 know some simple code for stopping alphabetical data being entered into a textbox. And allowing numerical data :thumb:
Got any ideas, my last try was:
VB Code:
Private Sub txtContactno_KeyPress(KeyAscii As Integer)
End Sub
the above code is backwards, it stops numerics
try
VB Code:
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
End If
rgds pete
Re: Simple Is numeric statement :mad:
You might want to try the link to my NumberBox control in my signature.
Re: Simple Is numeric statement :mad:
Dear Martin
Ya it is true, said codes are belong to your control exactally, but it is clear in my mind only to help some one and i hav't the reference of these code.