以下为当在text1中按下按键时,判断是否为m或M,如果是,则屏蔽输入
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "m" Or Chr(KeyAscii) = "M" Then
KeyAscii = 0
End If
End Sub
以下为判断文本框是否包含字符
Private Sub Command1_Click()
If InStr(LCase(Text1.Text), "m") > 0 Then '当包含m或M时
'包含
Else
'不包含
End If
End Sub
追问谢谢您的回答。如果我还想同时检查是否只有一个m,应该怎么写呢,谢谢
追答Dim i As Integer
i = InStr(Text1.Text, "m")'m在字符串中的位置,
If InStr(i + 1, Text1.Text, "m") > 0 Then'从i+1开始判断
MsgBox "还有m"
Else
MsgBox "没有了"
End If