VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Validates Number entered on a textbox Like CALC. during the keypress event!

by Rhian Aseniero (8 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 4th September 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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!



'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



Download this snippet    Add to My Saved Code

Validates Number entered on a textbox Like CALC. during the keypress event! Comments

No comments have been posted about Validates Number entered on a textbox Like CALC. during the keypress event!. Why not be the first to post a comment about Validates Number entered on a textbox Like CALC. during the keypress event!.

Post your comment

Subject:
Message:
0/1000 characters