Solved

Opposite of Hex function?

Posted on 1998-02-01
1
481 Views
Last Modified: 2012-08-14
Hello all!
I am wondering if there is any opposite of the Hex function?
Ex. Hex(255) returns FF.
Then should ThatFunction(FF) return 255!
0
Comment
Question by:martinag
1 Comment
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
ID: 1454797
Function HexStringToDecimal(Hex As String) As Long

   Dim strIn$, i&, j&, k&, c$
   strIn = Trim$(Hex)
   If Len(strIn) > 8 Then
      'Overflow
      Exit Function
   End If
   For i = Len(strIn) To 1 Step -1
      c = UCase(Mid$(Hex, i, 1))
      Select Case c
         Case "0" To "9"
            k = k + CLng(c) * 16 ^ j
         Case "A" To "F"
            k = k + (Asc(c) - 55) * 16 ^ j
         Case Else
            'Invalid character Error
            Exit Function
      End Select
      j = j + 1
   Next
   HexStringToDecimal = k

End Function

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

680 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