Results 1 to 6 of 6
  1. #1
    darvis_aurian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    3

    Converting Hexadecimal to decimal


    Hi All, How to convert Hexadecimal to decimal? I've tried use Val() to get the value but some value is not valid Help me please..

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Your question although specific is what you want is a little complicated, also missing some information.

    Do you want to convert it for every entry in a table, or do you just want it to convert one number at a time?
    Are the numbers fixed length or variable?
    Are the numbers stored as a single string (if appropriate)?

    Val returns the numbers in a string and stops returning numbers once it hits a non numeric character, see http://www.techonthenet.com/access/f...umeric/val.php

    A paper method for converting hexadecimal to decimal is located at http://www.webelfin.com/webelfindesign/hexdec.html (first example)

    With a bit more clarification we might be able to help a bit more.

  3. #3
    darvis_aurian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    3
    Yes, I want to convert it for every entry in a table, and the numbers is fixed length, just a simple program.

    Now I use command Val("&h" & [FieldName]). only a few results that have the wrong values​​, most of the results are correct, as I said before.

    for example : 9FD9 (Hex) after we convert to decimal the result should be 40921 (Dec), but in my query the result is -24615

    Do I need a complex script or just need a basic command in MS. Access?

    Many Thanks!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    see http://support.microsoft.com/kb/161304

    Code:
     Function HexToLong(ByVal sHex As String) As Long 
            HexToLong = Val("&H" & sHex & "&")       
    End Function

  5. #5
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    This is why i love orange!

  6. #6
    darvis_aurian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    3
    Quote Originally Posted by orange View Post
    see http://support.microsoft.com/kb/161304

    Code:
     Function HexToLong(ByVal sHex As String) As Long 
            HexToLong = Val("&H" & sHex & "&")       
    End Function
    Great!! problem has been solved by orange

    Thanks Master!!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Report decimal places
    By jackyoung2012 in forum Reports
    Replies: 1
    Last Post: 03-22-2012, 12:12 PM
  2. Limiting decimal places
    By Cran29 in forum Access
    Replies: 13
    Last Post: 01-08-2011, 08:01 AM
  3. Need Currency or Decimal Help!
    By Jaricketts in forum Access
    Replies: 2
    Last Post: 08-19-2010, 09:39 PM
  4. Converting HH:MM to decimal
    By katrinanyc926 in forum Queries
    Replies: 5
    Last Post: 08-13-2010, 02:39 PM
  5. Decimal seperator between different languages
    By seshan in forum Programming
    Replies: 3
    Last Post: 01-31-2010, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums