我就照这个大哥教的作了 Private Sub Form_Load() Check1.Caption = "英文" Check2.Caption = "数字" Check1.Value = 1 Check2.Value = 1 Text1.Text = "" flg = True End SubPrivate Sub Text1_Change() If Not flg And Len(Text1.Text) >= 1 Then Text1.Text = Replace(Text1.Text, Chr(k_code), "") flg = True k_code = "" Text1.SelStart = Len(Text1.Text) End If End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57 If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False: k_code = KeyAscii Case 65 To 90, 97 To 122 If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False: k_code = KeyAscii Case Else MsgBox "非法字符!": flg = False: k_code = KeyAscii End Select If KeyAscii >= 97 And KeyAscii <= 122 Then KeyAscii = KeyAscii - 32 End If End Sub 这里面有什么错么?我气是只想要得到这样的结果 ,就是两个textbox里面都能输入ZA123或者12345,但是*/-什么的输入就出现msgbox 提示输入错误。结果现在只能输入1个数,郁闷的要死
你的做法怪异! Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57 If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False: KeyAscii=0 Case 65 To 90, 97 To 122 If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False: KeyAscii=0 Case Else MsgBox "非法字符!": flg = False: KeyAscii=0 End Select If KeyAscii >= 97 And KeyAscii <= 122 Then KeyAscii = KeyAscii - 32 End If End Sub 这样不就行了!
Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57 If Check2.Value <> 1 Then MsgBox "不能輸入數字": KeyAscii = 0
Case 65 To 90, 97 To 122 If Check1.Value <> 1 Then MsgBox "不能輸入英文": KeyAscii = 0
Case KeyAscii <> 8 Or KeyAscii <> 13 '不能把刪除鍵和回車鍵屏閉了 '8 BackSpace,13 Enter MsgBox "非法字符!": KeyAscii = 0 End Select
If KeyAscii >= 97 And KeyAscii <= 122 Then KeyAscii = KeyAscii - 32 End IfEnd Sub Text_Change用不上
Private Sub Form_Load() Text1.Text = "" Text2.Text = "" End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57,65 To 90, 97 To 122 If KeyAscii >= 97 Then KeyAscii = KeyAscii - 32 Case Else MsgBox "非法字符!": KeyAscii =asc(vbnullstring) End Select End Sub
Private Sub Form_Load()
Check1.Caption = "英文"
Check2.Caption = "数字"
Check1.Value = 1
Check2.Value = 1
Text1.Text = ""
flg = True
End SubPrivate Sub Text1_Change()
If Not flg And Len(Text1.Text) >= 1 Then
Text1.Text = Replace(Text1.Text, Chr(k_code), "")
flg = True
k_code = ""
Text1.SelStart = Len(Text1.Text)
End If
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False: k_code = KeyAscii
Case 65 To 90, 97 To 122
If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False: k_code = KeyAscii
Case Else
MsgBox "非法字符!": flg = False: k_code = KeyAscii
End Select
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
End Sub
这里面有什么错么?我气是只想要得到这样的结果 ,就是两个textbox里面都能输入ZA123或者12345,但是*/-什么的输入就出现msgbox 提示输入错误。结果现在只能输入1个数,郁闷的要死
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False: KeyAscii=0
Case 65 To 90, 97 To 122
If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False: KeyAscii=0
Case Else
MsgBox "非法字符!": flg = False: KeyAscii=0
End Select
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
End Sub
这样不就行了!
Select Case KeyAscii
Case 48 To 57
If Check2.Value <> 1 Then MsgBox "不能輸入數字": KeyAscii = 0
Case 65 To 90, 97 To 122
If Check1.Value <> 1 Then MsgBox "不能輸入英文": KeyAscii = 0
Case KeyAscii <> 8 Or KeyAscii <> 13 '不能把刪除鍵和回車鍵屏閉了
'8 BackSpace,13 Enter
MsgBox "非法字符!": KeyAscii = 0
End Select
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End IfEnd Sub
Text_Change用不上
Text1.Text = ""
Text2.Text = ""
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57,65 To 90, 97 To 122
If KeyAscii >= 97 Then KeyAscii = KeyAscii - 32
Case Else
MsgBox "非法字符!": KeyAscii =asc(vbnullstring)
End Select
End Sub