这是我在网上搜的,每行什么意思,在后面注释一下
Public Function StrToHex(ByVal strS As String) As String
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
End Function
如果想在vb text中输入的姓名,性别,职位转换成16进制怎么写?
Public Function StrToHex(ByVal strS As String) As String
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
End Function
如果想在vb text中输入的姓名,性别,职位转换成16进制怎么写?
返回按指定类型转换的 Variant (String)。
Hex 函数
返回代表十六进制数值的 String。
Right 函数
返回 Variant (String),其中包含从字符串右边取出的指定数量的字符。Option Explicit
Dim strS As StringPublic Function StrToHex(ByVal strS As String) As String
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
Text2.Text = StrToHex
End FunctionPrivate Sub Command1_Click()
strS = Text1.Text
Call StrToHex(strS)
End Sub
当然是,上机实践下就知道了.输出在Text2中.
姓名 = StrToHex(姓名.text)
性别 = StrToHex(性别.text)
职位 = StrToHex(职位.text)
Dim strTemp As String
Dim strH As String
Dim L As Long
Dim i As Long
strTemp = StrConv(strS, vbFromUnicode)
L = LenB(strTemp)
For i = 1 To L
strH = strH & Right("0" & Hex(AscB(MidB(strTemp, i, 1))), 2)
Next
StrToHex = strH
End Function