HEX2DEC Update query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table that contains a field for the RAM of a given machine and it is
stored in HEX. I have created a new column and want to use an update query to
populate the new column with the RAM in decimal format. Can I do this using
an update query or do I have to incorporate Excel? Thanks for your help?
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can use an UPDATE query. The hard part will be converting HEX to
decimal. Here is a function from MS NeatCode .mdb file:

=== begin quote ===
Function Hex2Dec(strValue As String) As Long
On Error GoTo CnvrtErr
'
' Converts a string of hexadecimal digits into a decimal number.
' Valid input range '0' to '7FFFFFFF'
'
' Check to see if string already begins with &H.
If left(strValue, 2) <> "&H" Then strValue = "&h" & strValue

' Check to see if string contains Decimals and strip them out.
If InStr(1, strValue, ".") Then strValue = left(strValue, (InStr(1,
strValue, ".") - 1))

Hex2Dec = CLng(strValue)
Exit Function

CnvrtErr:
Hex2Dec = 0

End Function
=== end quote ===

You'll have to call the function in the UPDATE query like this:

UPDATE table_name
SET Decimal_Column = Hex2Dec(Hex_Column)
WHERE ... your criteria ...

The Decimal_Column should be a Long data type.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQRls34echKqOuFEgEQJunwCeLFC9SbI23ZeyH6g0dTXrvxmFUPIAoKGs
4AiBGuis7fsNiUDA8ekmB1ei
=ryd0
-----END PGP SIGNATURE-----
 
Hi,



Int("&h" & HexaString )

as:

? Int("&h" & "FF")


You can use CDec instead of Int. It is based on the fact that an hexa
constant an by typed directly, while preceded by &h, such as:


&hFF

or


&hFF00FF00


You can use Hex( ) for the reverse (from decimal to a string in hexa).


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top