写这样一个函数'参数sstr是要转换的字符串,shex是用十六进制还是用十进制显示转换后的字符串Public Function strtoasc$(ByVal sstr$, Optional ByVal sHex As Boolean = True) Dim i&, ire$ If sHex Then '用十六进制表示 For i = 1 To LenB(sstr) ire = ire & Hex(AscB(MidB(sstr, i, 1))) Next Else '用十进制表示 For i = 1 To LenB(sstr) ire = ire & AscB(MidB(sstr, i, 1)) Next End If strtoasc = ire End Function
如果你中是想得到单个字符的ASCII,就直接用 asc("a") '得到a的ascii码
首先设计两个文本匡 一个输入字符,另一个显示ascii码 Private Sub Text1_KeyPress(KeyAscii As Integer) Text2.Text = Str(KeyAscii) End Sub
Dim i&, ire$
If sHex Then '用十六进制表示
For i = 1 To LenB(sstr)
ire = ire & Hex(AscB(MidB(sstr, i, 1)))
Next
Else '用十进制表示
For i = 1 To LenB(sstr)
ire = ire & AscB(MidB(sstr, i, 1))
Next
End If
strtoasc = ire
End Function
asc("a") '得到a的ascii码
一个输入字符,另一个显示ascii码
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text2.Text = Str(KeyAscii)
End Sub