Private Sub Form_Load() Dim a As String Dim as1() As String Dim ab() As Byte a = "B1 82 45 9B 00 00 00 00" as1 = Split(a," ") ReDim ab(UBound(as1)) For i = 0 To UBound(as1) - 1 ab(i) = CByte(Val("&h" & as1(i))) Next a = ab End Sub
换成函数
Function HexToUnicode(inname As String) As String Dim a As String Dim as1() As String Dim ab() As Byte a = inname as1 = Split(a," ") ReDim ab(UBound(as1)) For i = 0 To UBound(as1) - 1 ab(i) = CByte(Val("&h" & as1(i))) Next HexToUnicode = ab End Function
strtohex
Function StrToHex(inname As String) As String Dim abyte1() As Byte abyte1 = inname For i = 0 To UBound(abyte1) StrToHex = StrToHex & Hex(abyte1(i)) Next End Function