自己写的两个函数,用于字符串和16进制互转换的,支持中文转换,中文编码写入IC卡非常方便
Public Function StrToHex(ByVal strS As String) As String
'将字符串转换为16进制
Dim abytS() As Byte
Dim bytTemp As Byte
Dim strTemp As String
Dim lLocation As Long
abytS = StrConv(strS, vbFromUnicode)
For lLocation = 0 To UBound(abytS)
bytTemp = abytS(lLocation)
strTemp = Hex(bytTemp)
strTemp = Right("00" & strTemp, 2)
StrToHex = StrToHex & strTemp
Next lLocation
StrToHex = StrToHex
End Function
Public Function HexToStr(str As String) As String
'将16进制转换为字符串
Dim rst() As Byte
Dim i As Long, j As Long, strlong As Long
strlong = Len(str)
ReDim rst(strlong \ 2)
For i = 0 To strlong - 1 Step 2
Dim tmp As Long
rst(i / 2) = Val("&H" & Mid(str, i + 1, 2))
Next
HexToStr = StrConv(rst, vbUnicode)
End Function