Solved

Converting HEX values

Posted on 1998-06-30
5
505 Views
Last Modified: 2012-08-14
I am going to extract HEX values from a file that is dumped from EPROM's.
Most of this values are to be extracted as Int or Long.
However, some of this values are to be converted to ASCII characters, and that's stopping me at the moment.
Is there any easy solution ?
0
Comment
Question by:rus
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 1464591
Do you mean the Hex values will be in the form of Hex number strings e.g. "1AB2" etc

If so answer to follow
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1464592
Private Function Hex_to_int(sX As String) As Long

    Dim sAtom As String
    Dim c As Integer
    Dim mFactor As Long
   
    mFactor = 1
   
   
    For c = Len(sX) To 1 Step -1
       
        sAtom = UCase(Mid(sX, c, 1))
       
        If sAtom >= "0" And sAtom <= "9" Then
           
            Hex_to_int = Hex_to_int + Val(sAtom) * mFactor
           
        Else
       
            Hex_to_int = Hex_to_int + (Asc(sAtom) - Asc("A") + 10) * mFactor
           
        End If
       
        mFactor = mFactor * 16
       
    Next
           

End Function


Private Sub Command1_Click()
   
    MsgBox Str(Hex_to_int("abc1"))   'displays 43969
   
End Sub

0
 

Author Comment

by:rus
ID: 1464593
Yes, The Hex values is like "1AB2" etc.
In VB there is a HEX-function but it returns a string with the hexadecimal value of a number. I would like it the other way,
Hexadecimal to number. In that way I should be able to extract the ascii characters by using the Chr-function.
Don't you think that...
0
 
LVL 18

Expert Comment

by:deighton
ID: 1464594
if you want a string instead of a long you could change the function to AS STRING then return cStr(long_integer) as the return value.  
0
 

Author Comment

by:rus
ID: 1464595
I have tested it an it's working fine, Thanks!

Best regards
Rudolf Stoum
Trondheim
Norway
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now