- Home
·
- Math/Dates
·
- Validates Number entered on a textbox Like CALC. during the keypress event!
Validates Number entered on a textbox Like CALC. during the keypress event!
Validates Number entered on a textbox Like CALC. during the keypress event!
Rate Validates Number entered on a textbox Like CALC. during the keypress event!
(1(1 Vote))
'copy and paste the code!
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then
If Text1 = "" Then Text1.Text = "0."
If InStr(1, Text1, ".") Then
KeyAscii = 0
End If
ElseIf (KeyAscii < 48 Or KeyAscii > 57) And Not KeyAscii = 8 And Not KeyAscii = 13 Then
KeyAscii = 0
Else
If KeyAscii = 48 Then
If Mid(Text1, 1, 1) = 0 Then
Text1.Text = "0."
KeyAscii = 0
End If
End If
If Mid(Text1, 1, 1) = "0" And Text1.SelStart = 1 Then
KeyAscii = 0
End If
'option for next focus
' if keyascii = 13 then
' setfocus
' end if
End If
End Sub
'Happy programming - Maayong Buntag! Rhian Aseniero
Validates Number entered on a textbox Like CALC. during the keypress event! Comments
No comments yet — be the first to post one!
Post a Comment