Solved

Converting HEX values

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

726 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