PDA

Click to See Complete Forum and Search --> : How To convert Hex to Dec in VB6.0?


elpower
Aug 23rd, 2000, 10:55 PM
Hi Guys,

I need to know how to convert Hexidecimal into decimal in Vb6.0
I am receiving data from my comm port in Text and there are some values that are in Hex. but i need the numeric value of them.

is that a command of module that i can use to do this?
let me know.

Thanks in advance.
EL.

Mark Sreeves
Aug 24th, 2000, 06:33 AM
I don't think VB has a built-in hex to dec function

Here's one I just knocked-up:



Public Function HextoDec(HexNum As String) As Long
Dim lngOut As Long
Dim i As Integer
Dim c As Integer

For i = 1 To Len(HexNum)
c = Asc(UCase(Mid(HexNum, i, 1)))
Select Case c

Case 65 To 70
lngOut = lngOut + ((c - 55) * 16 ^ (Len(HexNum) - i))

Case 48 To 57
lngOut = lngOut + ((c - 48) * 16 ^ (Len(HexNum) - i))

Case Else


End Select
Next i
HextoDec = lngOut
End Function

Javier Reinoso
May 6th, 2012, 03:18 PM
More simple:

DecNumber& = CLng("&H" & HexNum$)

szlamany
May 6th, 2012, 05:45 PM
Wow - and this thread is over 10 years old.

Do you really want to start with threads this old :rolleyes:

Javier Reinoso
May 6th, 2012, 06:40 PM
Wow - and this thread is over 10 years old.

Do you really want to start with threads this old

Because I search for this code and lost time, the two threads I answer are old but first in the search of google for this conversion, and for other people not lost time, the last instruction is the best, I test various, and this is simple, fast and totally operative...

Is the reason, for people that search this conversion, have fast and simple and good solution...

Sorry for my bad English...

Pd: Many persons use VB6, is old, but very usseful, I for example have a program in virtual machine - in a oracle sun virtualbox portable - that I sell, and in the virtual machine have a Windows XP 32 bits, and for this operative system, vb6 is fast and a good solution... And in the virtual machine my program run without changes, worked for decades is possible, and I not lost time in the changes of different versions of windows and changes and craps of microsoft...

Also in virtualbox machine is possible for my sell the program for mac and for linux, good solution without need to create 3 programs... One for each system...

One of the big problems of the programation is that is impossible arrive to a be master master master because each little time, changes, changes, changes, and the programmer need to create a good software of any thing, not lost your time in known new codes all the time...

I with the solution of virtualbox portable, is possible for me put all my time in make a better program, not lose all my time in known the stupids and always changes of microsoft...