Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Hex to Decimal Conversion
View previous topic :: View next topic  
Author Message
CheatKing64
Freshman


Joined: 06 Aug 2004
Posts: 32
Location: The US of A

PostPosted: Aug 23rd, 2004 02:40 PM    Post subject: Hex to Decimal Conversion Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Aug 24th, 2004 09:31 AM    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
CheatKing64
Freshman


Joined: 06 Aug 2004
Posts: 32
Location: The US of A

PostPosted: Aug 24th, 2004 10:23 AM    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Aug 24th, 2004 12:49 PM    Post subject: Reply with quote

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
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Aug 25th, 2004 05:21 PM    Post subject: Reply with quote

Oh, sorry... Never mind Smile
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
TriSight
Regular


Joined: 12 Oct 2004
Posts: 69
Location: Mobile, AL

PostPosted: Oct 22nd, 2004 10:14 AM    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Oct 22nd, 2004 02:07 PM    Post subject: Reply with quote

[vb:1:8a2f03b9e0]Private Sub Form_Load()
MsgBox Val("&HBB")
End Sub[/vb:1:8a2f03b9e0]

Biggrin
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic