Solved

Converting HEX values

Posted on 1998-06-30
5
504 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now