读书人

只允许输入汉字在提交的时候提醒,该怎

发布时间: 2012-03-13 11:21:12 作者: rapoo

只允许输入汉字在提交的时候提醒
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > 0 And KeyAscii <> 13 And KeyAscii <> 8 Then
KeyAscii = 0
MsgBox "只允许输入汉字! ", 48, "提示 "
End If
End Sub
这是输入时提醒,不太方便
Case "ok "代表提交保存,之后要检验是否输入汉字按如何写代码,

[解决办法]
‘我说过了,在要输入时提醒,我要提交确定按钮时才提醒呀’

无言。你自己改一点嘛,脑在你脖子上。

不过还是给你怎样判断是非是Chinese Characters

Public Function isChinese(ByVal asciiv As Integer) As Boolean
If Len(Hex$(asciiv)) > 2 Then
isChinese = True
Else
isChinese = False
End If
End Function


[解决办法]
把判断的代码放在Validate事件中去执行:

Private Sub Text1_Validate(Cancel As Boolean)
If Len(Text1.Text) * 2 <> LenB(StrConv(Text1.Text, vbFromUnicode)) Then
MsgBox "输入的内容必须全部是汉字 "
Cancel = True
End If
End Sub

读书人网 >VB

热点推荐