Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii < 0 Then MsgBox "汉字" Else MsgBox "非汉字" End IfEnd Sub
用区位码判断!!if Hex(Asc(lstmp)) < &H80 then '非汉字 else '汉字 endif
Private Function CtoU(ByVal Rstr As String) As String Dim jj As Long, lenRstr As Long Dim TempStr As String'A转为U码不带前后缀 lenRstr = Len(Rstr) If Len(Rstr) = 0 Then GoTo charerrFor jj = 1 To lenRstr TempStr = StrToUnicode(Mid(Rstr, jj, 1)) If TempStr <> "" Then CtoU = CtoU & TempStr Else GoTo charerr End If Next jjExit Function charerr: CtoU = "" End FunctionPrivate Function StrToUnicode(ByVal strIn As String) As String Dim buf() As Byte Dim i As Long Dim tempT As String '中文转成Un码的过程,单个地转 On Error GoTo trunerrbuf = strIn For i = 0 To 1 tempT = Hex(buf(i)) If Len(tempT) = 1 Then tempT = "0" & tempT StrToUnicode = tempT & StrToUnicode Next iIf Len(StrToUnicode) < 4 Then StrToUnicode = strIn End IfExit Function trunerr: StrToUnicode = "" End Function 判断汉字:
a="汉" if ctou(a)>="3000" and ctou(a)<="9FFF" then msgbox "这个是汉字" endif
如果s是unicode,lenb函数等于2,否则等于1。ps:unicode并不代表就是汉字。
MsgBox "汉字"
Else
MsgBox "非汉字"
End IfEnd Sub
'非汉字
else
'汉字
endif
Dim jj As Long, lenRstr As Long
Dim TempStr As String'A转为U码不带前后缀
lenRstr = Len(Rstr)
If Len(Rstr) = 0 Then GoTo charerrFor jj = 1 To lenRstr
TempStr = StrToUnicode(Mid(Rstr, jj, 1))
If TempStr <> "" Then
CtoU = CtoU & TempStr
Else
GoTo charerr
End If
Next jjExit Function
charerr:
CtoU = ""
End FunctionPrivate Function StrToUnicode(ByVal strIn As String) As String
Dim buf() As Byte
Dim i As Long
Dim tempT As String
'中文转成Un码的过程,单个地转
On Error GoTo trunerrbuf = strIn
For i = 0 To 1
tempT = Hex(buf(i))
If Len(tempT) = 1 Then tempT = "0" & tempT
StrToUnicode = tempT & StrToUnicode
Next iIf Len(StrToUnicode) < 4 Then
StrToUnicode = strIn
End IfExit Function
trunerr:
StrToUnicode = ""
End Function
判断汉字:
a="汉"
if ctou(a)>="3000" and ctou(a)<="9FFF" then
msgbox "这个是汉字"
endif