Hi there,
is there any possibility to restrict input of a text field to integers and one point only (so that you are able to display decimals e.g. 0.23).
Does someone know how to do so?
Thx
Charly
Printable View
Hi there,
is there any possibility to restrict input of a text field to integers and one point only (so that you are able to display decimals e.g. 0.23).
Does someone know how to do so?
Thx
Charly
CHECK THE ASCII IN TEXTBOX'S CHANGE EVENT AND KEYPRESS EVENT
VB Code:
Private Sub txtCPin_KeyPress(KeyAscii As Integer) If KeyAscii = 8 Then Exit Sub If Not (KeyAscii > 47 And KeyAscii < 58) Then If Not (KeyAscii =46) Then KeyAscii = 0 end if end if
Gary
Or...
Code:Private Sub Text1_Change()
If Text1.Text = "" Then Exit Sub
If Not IsNumeric(Text1.Text) Then
MsgBox "Please enter a number only"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
or use a masked edit box if your version of VB came with it.
Code:Private Sub Text1_Change()
If Text1.Text = "" Then Exit Sub
If Not IsNumeric(Text1.Text) Or InStr(1, Text1.Text, ".") > 0 Then
MsgBox "Please enter an integer number only"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii <> vbKeyBack And KeyAscii <> vbKeyReturn And KeyAscii <> vbKeyEscape Then If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then If KeyAscii = Asc(".") Then If InStr(1, Text1.Text, ".") <> 0 Then KeyAscii = 0 End If Else KeyAscii = 0 End If End If End If End Sub
.