Private Sub TEXTBOX_KeyPress(Index As Integer, KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
Beep
Exit Sub
End If
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
Beep
Exit Sub
End If
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
testbox.text=""
testbox.setfocus
Exit Sub
End If
End Sub
Private Sub txtAge_KeyPress(KeyAscii As Integer)
If Not ((Chr(KeyAscii) Like "[0-9]") Or KeyAscii = 8) Then
KeyAscii = 0
End If
End Sub
给你一个非常简单的代码!
////////只可以输入数字,如果想输入退格键的话在if语句加上去就OK了!/////
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > vbKey0 Or KeyAscii < vbKey9 Then
Else: KeyAscii = 0
End If
End Sub
////////////////////////////////////////////////////////////
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const ES_NUMBER = &H2000Private Sub Form_Load()
SetWindowLong TEXTBOX.hwnd, GWL_STYLE, GetWindowLong(TEXTBOX.hwnd, GWL_STYLE) Or ES_NUMBER
End Sub