Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text2.Text = MyChr(KeyAscii)
End Sub
Private Function MyChr(ByVal CharCode As Long) As String
Dim a(0 To 1) As Byte, b As Byte
CopyMemory a(0), CharCode, 2
If CharCode < 0 Then
b = a(0)
a(0) = a(1)
a(1) = b
End If
MyChr = StrConv(a, vbUnicode)
End Function
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text2.Text = MyChr(KeyAscii)
End Sub
Private Function MyChr(ByVal CharCode As Long) As String
Dim a(0 To 1) As Byte, b As Byte
CopyMemory a(0), KeyAscii, 2
If KeyAscii < 0 Then
b = a(0)
a(0) = a(1)
a(1) = b
End If
MyChr = StrConv(a, vbUnicode)
End Function
1. "小"的汉字内码 D0A1(即两个字节分别为208,161),而 &HD0A1=-12127,它的UNICODE编码就是"小"
Private Sub Command1_Click()
Dim b(1) As Byte
b(0) = 208 'HD0
b(1) = 161 ' HA1
MsgBox StrConv(b, vbUnicode)
End Sub
Function quwei(ByVal x As String) As String '获得某汉字或字符对应的的区位码
If Asc(x) >= 0 Then Exit Function
x = Hex(Asc(x))
quwei = Format(CDec("&H" & Left(x, 2)) - 160, "00") & Format(CDec("&H" & Right(x, 2)) - 160, "00")
End Function
Function hanzi(ByVal x As String) As String '获得某区位码对应汉字或字符
hanzi = Chr("&H" & Hex(Val(Left(x, 2)) + 160) & Hex(Val(Right(x, 2)) + 160))
End Function