大家哪位高手帮小弟我改一下下面这代码,改得效率高点
大家谁帮我改一下下面这代码,改得效率高点
其它s固定为2个字符的字符串(如00, 01, 09, A0, A9, BB, D9, EF等),
用于返回其对应的HEX的十进制
怎么做效率高一点?
Public Function stohex(ByVal s As String) As Integer
Dim stemp As String
ss = s
If Len(ss) = 2 Then
If Mid(ss, 1, 1) = "0 " Then
ss = Mid(ss, 2, 1)
End If
End If
For i = 0 To 10000
stemp = UCase(hex(i))
If stemp = UCase(ss) Then
stohex = i
Exit Function
End If
Next i
stohex = -1
End Function
------解决方案--------------------
s = "FF "
i = Val( "&H " + s)
MsgBox Str(i)
------解决方案--------------------
Dim ss As String * 2, i As Integer
ss = "af "
i = "&h " & ss
Print i
其它s固定为2个字符的字符串(如00, 01, 09, A0, A9, BB, D9, EF等),
用于返回其对应的HEX的十进制
怎么做效率高一点?
Public Function stohex(ByVal s As String) As Integer
Dim stemp As String
ss = s
If Len(ss) = 2 Then
If Mid(ss, 1, 1) = "0 " Then
ss = Mid(ss, 2, 1)
End If
End If
For i = 0 To 10000
stemp = UCase(hex(i))
If stemp = UCase(ss) Then
stohex = i
Exit Function
End If
Next i
stohex = -1
End Function
------解决方案--------------------
s = "FF "
i = Val( "&H " + s)
MsgBox Str(i)
------解决方案--------------------
Dim ss As String * 2, i As Integer
ss = "af "
i = "&h " & ss
Print i