For basic code you can using below code :
Private Sub Text1_KeyPress(KeyAscii As Integer)For example, you can design form in VB 6.0 like below picture
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then KeyAscii = 0
End Sub
In Price (Text3) and Quantity (Text4) we will validate only numeric can input data in Text, so you can insert below code in Form1 :
Private Sub Form_Load()After that, please run your VB 6.0 Project :)
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then KeyAscii = 0
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then KeyAscii = 0
End Sub
0 Response to "VB 6.0 - How to only allow numeric values in the TextBox"