文本框的KeyPress事件: Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) Then KeyAscii = 0 End If End Sub
Private Sub Command1_Click() If IsNumeric(Text1.Text) Then MsgBox "数字" Else MsgBox "字母" End IfEnd Sub
Text1只能输入数字 Private Sub Text1_KeyPress(KeyAscii As Integer) Dim Numbers As String Numbers = "1234567890" + Chr(8) + Chr(46) If InStr(Numbers, Chr(KeyAscii)) = 0 Then KeyAscii = 0 End If End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If isnumeric(chr(keyascii))=false Then KeyAscii = 0 End If End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) Then
KeyAscii = 0
End If
End Sub
If IsNumeric(Text1.Text) Then
MsgBox "数字"
Else
MsgBox "字母"
End IfEnd Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim Numbers As String
Numbers = "1234567890" + Chr(8) + Chr(46)
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
If isnumeric(chr(keyascii))=false Then
KeyAscii = 0
End If
End Sub
你要实现的条件
else
___
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer