Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VB Script to Convert a Hexidecimal Value to a Decimal Value

VB Script to Convert a Hexidecimal Value to a Decimal Value

'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


How helpful was this article to you?

Related Articles

article How to Convert DNS Primary Server to Active Directory Integrated
You may want to add additional DNS servers so...

(No rating)  6-3-2008    Views: 61   
article How to Convert Physical Machines to Virtual Machines using VMware Converter
VMware has recently announced a new product...

(No rating)  4-12-2008    Views: 272   
article VB Script for EventLogging
Set WshShl =...

(No rating)  3-24-2008    Views: 97   

User Comments

Add Comment
No comments have been posted.