?
Solved

Converting HEX values

Posted on 1998-06-30
5
Medium Priority
?
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

762 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