# VB script for Hexadecimal usage

Hi,

We have a hexadecimal like  0C0BA715B2223D47A8CACA87BE5D9679 . We want to use that in Vb script. We are not able to use that because it was taking only 8 bit values. So Could please tell us how can we use this kind of long hexadecimals in Vb script for assigning and addition.

###### Who is Participating?

Commented:
Here you go, large hex string addition where you keep the HEX values in strings:

0

Commented:
According to
http://support.microsoft.com/kb/279115

Use
MsgBox CLng("&h" & hex_value)

0

Author Commented:
COULD YOU PLEASE TELL ME HOW TO ASSIGN 32 DIGIT HEXADECIMAL VALUE ( LIKE 0C0BA715B2223D47A8CACA87BE5D9679 ) TO A VARIABLE.

I HAVE TRIED  THIS WAY
DIM X= &h123AB344
ITS EXACTLY TAKING 8 DIGITS ELSE IT IS SAYING SYNTAX ERROR
PLEASE LET ME KNOW HOW TO PROCEED FURTHER...
0

Commented:
Try the modified solution from here: http://www.experts-exchange.com/Q_21716456.html
``````HexVal="0C0BA715B2223D47A8CACA87BE5D9679"

wscript.echo HexToDec (HexVal)

Function HexToDec(HexNum)
Dim x
Dim TempValue
Dim Digit
Dim DecValue

If UCase(Left(HexNum, 2)) = "&H" Then HexNum = Right(HexNum, Len(HexNum) - 2)

For x = Len(HexNum) To 1 Step -1
Digit = Mid(HexNum, x, 1)
If UCase(Digit) = "A" Then
TempValue = 10
ElseIf UCase(Digit) = "B" Then
TempValue = 11
ElseIf UCase(Digit) = "C" Then
TempValue = 12
ElseIf UCase(Digit) = "D" Then
TempValue = 13
ElseIf UCase(Digit) = "E" Then
TempValue = 14
ElseIf UCase(Digit) = "F" Then
TempValue = 15
ElseIf UCase(Digit) >= "0" And UCase(Digit) <= "9" Then
TempValue = Digit
Else
wscript.echo "Error in Hex string! (" & HexNum & ")"
Exit Function
End If

DecValue = DecValue + TempValue * 16 ^ (Len(HexNum) - x)
Next

HexToDec = DecValue
End Function
``````
0

Commented:
0

Author Commented:
I believe this converts hexadecimal value to decimal. but i directly want to increment the hex value...is there any possibility as such....if so please let us know.

Thanks for the response.
0

Author Commented:
Also how do i assign this 32digit hex value to a variable..bcoz by default it is taking only 8digits and also is there any static declaration kind of thing in vb like in "c" so that it retains latest value every time i run a script.

For ex: if today a variable contains 0 i run the  script and after increments and all the  latest value is 5
next time when i run the same script i should continue from 5 and not 0
0

Commented:
To answer your question about keeping the variable static it wouldn't work between runs unless you stored it off someplace because once the vbscript has completed it is removed from memory.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.