VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple Code to accept Only Numbers & decimal in a text box.

by Muhammad Asghar Shah (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 15th August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Simple Code to accept Only Numbers & decimal in a text box.

Rate Simple Code to accept Only Numbers & decimal in a text box.



Private Sub Text1_KeyPress(KeyAscii As Integer)
'When the user presses a key, check to insure the KeyAscii value is:
'  Between  48 - Ascii 0
'           57 - Ascii 9
'           8  - BackSpace
'           46 - Ascii .
      
   If InStr(Text1.Text, ".") And KeyAscii = 46 Then
       KeyAscii = 0
       Exit Sub
   End If
   
If Not ((KeyAscii > 48 And KeyAscii < 57) Or KeyAscii = 8 Or KeyAscii = 46) Then
   KeyAscii = 0  '0 is Ascii Null
End If

End Sub


Download this snippet    Add to My Saved Code

Simple Code to accept Only Numbers & decimal in a text box. Comments

No comments have been posted about Simple Code to accept Only Numbers & decimal in a text box.. Why not be the first to post a comment about Simple Code to accept Only Numbers & decimal in a text box..

Post your comment

Subject:
Message:
0/1000 characters