| View previous topic :: View next topic |
| Author |
Message |
CheatKing64 Freshman

Joined: 06 Aug 2004 Posts: 32 Location: The US of A
|
Posted: Aug 23rd, 2004 02:40 PM Post subject: Hex to Decimal Conversion |
|
|
I wrote this code to convert a Variant containing a Hex string to Decimal format (returns a Long).
[vb:1:fe1edf0aae]Function UnHex(what) As Long
Dim x As Long
For i = Len(what) To 1 Step -1
Select Case UCase(Mid(what, i, 1))
Case "A"
x = 10
Case "B"
x = 11
Case "C"
x = 12
Case "D"
x = 13
Case "E"
x = 14
Case "F"
x = 15
Case Else
x = Mid(what, i, 1)
End Select
x = x * 16 ^ (i - 1)
UnHex = UnHex + x
Next
End Function
[/vb:1:fe1edf0aae]
If you encounter any problems, let me know. It was tested using VB6, but I think it'll work in VB5 (anybody?) _________________ NCSA Certified in HTML 4.0:
EasyMail POP/SMTP Server:
http://easymail.sourceforge.net |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Aug 24th, 2004 09:31 AM Post subject: |
|
|
What about :
[vb:1:966241a587]MsgBox Val(hex stuff)[/vb:1:966241a587] _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
CheatKing64 Freshman

Joined: 06 Aug 2004 Posts: 32 Location: The US of A
|
Posted: Aug 24th, 2004 10:23 AM Post subject: |
|
|
I just tried that, but it returned 0 for "BB", which is hex for 187. Visual Basic just doesn't have a hex to decimal conversion function. _________________ NCSA Certified in HTML 4.0:
EasyMail POP/SMTP Server:
http://easymail.sourceforge.net |
|
| Back to top |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Aug 24th, 2004 12:49 PM Post subject: |
|
|
CheatKing64 is correct, you can get the Hex() of a number but not vice versa without some coding. _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Aug 25th, 2004 05:21 PM Post subject: |
|
|
Oh, sorry... Never mind  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
TriSight Regular
Joined: 12 Oct 2004 Posts: 69 Location: Mobile, AL
|
Posted: Oct 22nd, 2004 10:14 AM Post subject: |
|
|
This is what I use.. it's basically the same thing..
| Code: | Public Function Hex2Dec(ByVal strHex As String) As Long
Dim i As Integer
Dim lngDec As Long
For i = Len(strHex) To 1 Step -1
lngDec = lngDec + (InStr(1, "0123456789ABCDEF", Mid(strHex, i, 1)) - 1) * 16 ^ (Len(strHex) - i)
Next i
Hex2Dec = CStr(lngDec)
End Function |
_________________ /=--_The Nomad_--=\
"Men of lofty genius when they are doing the least work are most active. " - Leonardo da Vinci |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 22nd, 2004 02:07 PM Post subject: |
|
|
[vb:1:8a2f03b9e0]Private Sub Form_Load()
MsgBox Val("&HBB")
End Sub[/vb:1:8a2f03b9e0]
 _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
|