'HexToDec.vbs - Convert Hexadecimal value to Decimal value.
'© Bill James - bill@billsway.com - Rev 25 Oct, 2000
Option Explicit
Dim title, lf, HexVal, ErrMsg
title = "Hex to Dec Converter © Bill James"
lf = vbcrlf
GetInput()
Sub GetInput()
HexVal = UCase(InputBox(ErrMsg & "Enter a Hex value " & _
"to be converted to Decimal:", title))
ConvertHex()
End Sub
Sub ConvertHex()
Dim x, y, z, v
If HexVal = "" Then
WScript.Quit
Else
For x = 1 To Len(HexVal)
y = Mid(HexVal, ((Len(HexVal) - x) + 1), 1)
On Error Resume Next
v = CLng("&H" & y)
If Err.Number <> 0 Then
GetErrMsg()
Exit Sub
End If
On Error GoTo 0
z = z + (v * 16 ^ (x - 1))
Next
If Len(z) > 15 Then
MsgBox "Sorry, you exceeded my conversion capability with that one!" & _
lf & lf & vbtab & "(" & z & ")", 48, title
Else
HexVal = UCase(InputBox("Dec value for " & HexVal & " is:", title, z))
End If
End If
End Sub
Sub GetErrMsg()
ErrMsg = HexVal & " is an invalid Hex value." & lf & lf & _
"The only legal characters for a Hex number are " & lf & _
"0 1 2 3 4 5 6 7 8 9 A B C D E F" & lf & lf
GetInput()
End Sub