Subtract 2 hex fields for a report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kimmer
    New Member
    • Jul 2010
    • 9

    Subtract 2 hex fields for a report

    I have a database that has 2 8-character hex fields. I defined as TEXT. The field has leading blanks since hex field is right justified. I want to subtract the two fields for a report. I tried to convert the hex field to an integer using the VAL("&H[hexfield]") but it only returns the value 0. Is this because I have leading blanks? Any suggestions for this report field?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    The following Code will subtract 2, 8-Character Hexidecimal Values, and provide the correct results. Leading spaces will be irrelevant, and need not be trimmed:
    1. To return the Result in Decimal
      Code:
      Debug.Print FormatNumber(Val("&H" & "  1AD45C7E") - Val("&H" & "      12345C7F"),0)
      Debug.Print FormatNumber(Val("&H" & Me![txtHex1]) - Val("&H" & Me![txtHex2]), 0)
      Code:
      144,703,487
    2. To return the Result in Hexadecimal:
      Code:
      Debug.Print Hex$(Val("&H" & "  1AD45C7E") - Val("&H" & "      12345C7F"))
      Debug.Print Hex$(Val("&H" & Me![txtHex1]) - Val("&H" & Me![txtHex2]))
      Code:
      89FFFFF

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Kimmer,

      You were so close with :
      Code:
      VAL("&H[hexfield]")
      All ADezii did was to change this to :
      Code:
      VAL("&H" & [hexfield])
      Very little different as you can see.

      Welcome to Bytes!

      Comment

      Working...