changing the decimal to hex

  • Thread starter mohsin via AccessMonster.com
  • Start date
M

mohsin via AccessMonster.com

Hi all

Need your opinion for this queries,

In one of my field's table, i have mix hex and decimal value. Since i just
need only hex value in my queries, i need to convert or change the decimal to
hex. The possible function, in my mind is using function IIF([myfield] =
decimal,convert,[myfield])

the question is, how the access will check if the value is decimal or not?,
and then to convert the value, from decimal to hex.?

or any other's idea, appreciate for your help.

thank you
-mohsin
 
J

John Spencer

Not fully tested but you could try

IIF(IsNumeric([YourField]),Hex([YourField]),[YourField])


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
J

John W. Vinson

Hi all

Need your opinion for this queries,

In one of my field's table, i have mix hex and decimal value. Since i just
need only hex value in my queries, i need to convert or change the decimal to
hex. The possible function, in my mind is using function IIF([myfield] =
decimal,convert,[myfield])

the question is, how the access will check if the value is decimal or not?,
and then to convert the value, from decimal to hex.?

If your field contains the string "1FA3" then it's clearly hex... but what if
it contains "9836"? Is that decimal 9836 ('x266C') or is it hex 9836 (38966),
and how on Earth can you tell?

John W. Vinson [MVP]
 
J

John Spencer

Good Catch. I didn't even think of the possibility that a hex
representation could appear to be just a base ten number.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

John W. Vinson said:
Hi all

Need your opinion for this queries,

In one of my field's table, i have mix hex and decimal value. Since i just
need only hex value in my queries, i need to convert or change the decimal
to
hex. The possible function, in my mind is using function IIF([myfield] =
decimal,convert,[myfield])

the question is, how the access will check if the value is decimal or
not?,
and then to convert the value, from decimal to hex.?

If your field contains the string "1FA3" then it's clearly hex... but what
if
it contains "9836"? Is that decimal 9836 ('x266C') or is it hex 9836
(38966),
and how on Earth can you tell?

John W. Vinson [MVP]
 
J

Jamie Collins

If your field contains the string "1FA3" then it's clearly hex... but what if
it contains "9836"? Is that decimal 9836 ('x266C') or is it hex 9836 (38966),
and how on Earth can you tell?

Didn't you just answer your own question there? i.e. formatting
(&H0000266C&, &H266C&, etc).

I think the question is, why isn't the OP storing values using a
numeric type?

Jamie.

--
 
J

John Spencer

If the user is storing the Hex numbers with the &H prefix then my solution
would be

IIF(IsNumeric([TheField]),"&H" & Hex(CLng([TheField])),Null)

That changes the number to its base 10 equivalent and then changes that to
its hex equivalent. But if the number is not being stored with the prefix,
there is no way to handle the ambiguity inherent with 9836.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top