2个回答
展开全部
一个函数 IS_GBK_HZ ,返回是否为汉字。只能一个字符一个字符验证。
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As String, ByVal Length As Long)
'sHz只能为一个字符
Private Function IS_GBK_HZ(ByVal sHZ As String) As Boolean
Dim aHZ(1) As Byte
sHZ = Left(sHZ, 1)
If Len(sHZ) > 0 Then
CopyMemory aHZ(0), sHZ, 2
IS_GBK_HZ = (((aHZ(0) >= &H81) And (aHZ(0) < &HA1)) Or ((aHZ(0) >= &HAA) And (aHZ(0) < &HFE))) And (aHZ(1) >= &H40) And (aHZ(1) < &HFF)
End If
End Function
'测试
Private Sub Text1_Change()
Debug.Print Right(Text1.Text, 1) & " " & IS_GBK_HZ(Right(Text1.Text, 1))
End Sub
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As String, ByVal Length As Long)
'sHz只能为一个字符
Private Function IS_GBK_HZ(ByVal sHZ As String) As Boolean
Dim aHZ(1) As Byte
sHZ = Left(sHZ, 1)
If Len(sHZ) > 0 Then
CopyMemory aHZ(0), sHZ, 2
IS_GBK_HZ = (((aHZ(0) >= &H81) And (aHZ(0) < &HA1)) Or ((aHZ(0) >= &HAA) And (aHZ(0) < &HFE))) And (aHZ(1) >= &H40) And (aHZ(1) < &HFF)
End If
End Function
'测试
Private Sub Text1_Change()
Debug.Print Right(Text1.Text, 1) & " " & IS_GBK_HZ(Right(Text1.Text, 1))
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询