Function Hex2Dec(InputData As String) As Double
''
'' Converts Hexadecimal to Decimal
''
Dim I As Integer
Dim DecOut As Double
Dim Lenhex As Integer
Dim HexStep As Double
'' Zeroise the output
DecOut = 0
'' The length of the input
''
InputData = UCase(InputData)
Lenhex = Len(InputData)
''
'' Check to make sure its a valid Hex Number
''
For I = 1 To Lenhex
If IsNumeric(Mid(InputData, I, 1)) Then
''
GoTo NumOk
ElseIfmid(InputData, I, 1) = "A" Then
GoTo NumOk
ElseIfmid(InputData, I, 1) = "B" Then
GoTo NumOk
ElseIfmid(InputData, I, 1) = "C" Then
GoTo NumOk
ElseIfmid(InputData, I, 1) = "D" Then
GoTo NumOk
ElseIfmid(InputData, I, 1) = "E" Then
GoTo NumOk
ElseIfmid(InputData, I, 1) = "F" Then
GoTo NumOk
Else
MsgBox "Number given is not in Hex format", vbCritical
Exit Function
End If
NumOk:
Next I
HexStep = 0
''
''
'' Convert the Number to Decimal
''
For I = Lenhex To 1 Step -1
HexStep = HexStep * 16
If HexStep = 0 Then
HexStep = 1
End If
Ifmid(InputData, I, 1) = "0" Then
DecOut = DecOut + (0 * HexStep)
ElseIfmid(InputData, I, 1) = "1" Then
DecOut = DecOut + (1 * HexStep)
ElseIfmid(InputData, I, 1) = "2" Then
DecOut = DecOut + (2 * HexStep)
ElseIfmid(InputData, I, 1) = "3" Then
DecOut = DecOut + (3 * HexStep)
ElseIfmid(InputData, I, 1) = "4" Then
DecOut = DecOut + (4 * HexStep)
ElseIfmid(InputData, I, 1) = "5" Then
DecOut = DecOut + (5 * HexStep)
ElseIfmid(InputData, I, 1) = "6" Then
DecOut = DecOut + (6 * HexStep)
ElseIfmid(InputData, I, 1) = "7" Then
DecOut = DecOut + (7 * HexStep)
ElseIfmid(InputData, I, 1) = "8" Then
DecOut = DecOut + (8 * HexStep)
ElseIfmid(InputData, I, 1) = "9" Then
DecOut = DecOut + (9 * HexStep)
ElseIfmid(InputData, I, 1) = "A" Then
DecOut = DecOut + (10 * HexStep)
ElseIfmid(InputData, I, 1) = "B" Then
DecOut = DecOut + (11 * HexStep)
ElseIfmid(InputData, I, 1) = "C" Then
DecOut = DecOut + (12 * HexStep)
ElseIfmid(InputData, I, 1) = "D" Then
DecOut = DecOut + (13 * HexStep)
ElseIfmid(InputData, I, 1) = "E" Then
DecOut = DecOut + (14 * HexStep)
ElseIfmid(InputData, I, 1) = "F" Then
DecOut = DecOut + (15 * HexStep)
Else
MsgBox "Something is Screwed up, Wahhhhhhhhhhh", vbCritical
End If
Next I
Hex2Dec = DecOut
eds:
End Function
不是我做的,网上的