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?
Subtract 2 hex fields for a report
Collapse
X
-
-
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:- 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
- 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
- To return the Result in Decimal
Comment