Link to home
Start Free TrialLog in
Avatar of njacques
njacques

asked on

converting hex value to decimal value

i have a problem, in my app. i have to convert decimal to hex (no problem with hex(variable)) but i also want to do the opposite. I want to convert a hex value into a decimal value and i have not found any way to do it... help me..

p.s: i use vb-pro 3
ASKER CERTIFIED SOLUTION
Avatar of Johanl
Johanl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of njacques
njacques

ASKER

I cannot get you function to reply... I have placed it inside a module file (module1.bas) and the two function are contained into the pull down menu. so here is a part of my code..

If Len(text4.Text) < 6 Then
MsgBox ("Please enter a 6 digit hexadecimal number (RRGGBB)")
Exit Sub
End If

Dim rouge As String
Dim vert As String
Dim bleu As String
                 
rouge = UCase$(Left(text4.Text, 2))
vert = UCase$(Right(Left(text4.Text, 4), 2))
bleu = UCase$(Right(text4.Text, 2))

rougedec = HexToDec("rouge")

vertdec = HexToDec(vert)

bleudec = HexToDec(bleu)

label1.Caption = rougedec
label2.Caption = vertdec
label3.Caption = bleudec

hscroll1.Value = Val(rougedec)
hscroll2.Value = Val(vertdec)
hscroll3.Value = Val(bleudec)

the user enters a 6 digit string and the app split the rr-gg-bb so that they can be converted separatly. when the app get to you function call, the labels get blank... help me (am i using your function right) could my code cause this?

help me
rougedec=hextodec(rouge) and NOT rougedec=hextodec("rouge")

I've copied your code for testing and works fine.

Let know if it works now
Johan
i found out that val(&hff)
will do the job so o only got to do this

toconvert$ = "&h" + rouge
decimal = val(toconvert$)

and it converts, save a lot of time and coding

thanks anyway

bye