If KeyAscii > Asc(9) Or KeyAscii < Asc(0) Then KeyAscii = 0 End If
在delphi中我是这样做的,你可修改if not key in ['0'..'9','.','#8] then key:=#0;
Private Sub Text1_Change() If IsNumeric(Text1.Text) = False Then MsgBox "请输入数字" If Text1.Text <> "" Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End If End If End Sub
If KeyAscii > Asc(9) Or KeyAscii < Asc(0) Then Msgbox "这个文本框只能输入数字!!!",vbinformation,"提示" Text1.setfocus End If
Private Sub Text1_KeyPress(KeyAscii As Integer) If Chr(KeyAscii) Like "[0-9]" Or KeyAscii = vbKeyBack Then Else KeyAscii = 0 End If End Sub
If KeyAscii > Asc(9) Or KeyAscii < Asc(0) or keyascii<>asc(,) or keyascii<>asc(.) or keyascii<>8 Then KeyAscii = 0 End If
KeyAscii = 0
End If
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入数字"
If Text1.Text <> "" Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End If
End Sub
Msgbox "这个文本框只能输入数字!!!",vbinformation,"提示"
Text1.setfocus
End If
If Chr(KeyAscii) Like "[0-9]" Or KeyAscii = vbKeyBack Then
Else
KeyAscii = 0
End If
End Sub
KeyAscii = 0
End If