|
-
Jun 11th, 2002, 11:54 PM
#1
Thread Starter
Junior Member
Text Field, Integer only?
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
-
Jun 12th, 2002, 12:06 AM
#2
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
-
Jun 12th, 2002, 12:13 AM
#3
Hyperactive Member
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
Sometimes what you're looking for is exactly where you left it.
-
Jun 12th, 2002, 12:18 AM
#4
PowerPoster
or use a masked edit box if your version of VB came with it.
-
Jun 12th, 2002, 12:21 AM
#5
PowerPoster
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
-
Jun 12th, 2002, 03:21 AM
#6
Well ...
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
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|