taking a numeric field and converting it to hex

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

Guest

I also have a 11 digit numerical field on a form. I have a second field on my
form, where I would like to take the numeric number in that first field, and
populate this second field with the hexadecimal equivilent. Is there any
programming that anyone knows of that can do this?

Thanks again,

Richard
 
Richard

It is probably not necessary to have an additional field for the
hexadecimal representation. Just put an unbound textbox on the form,
and in its Control Source put the equivalent of...
=Hex([YourNumberField])
 
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?

Steve Schapel said:
Richard

It is probably not necessary to have an additional field for the
hexadecimal representation. Just put an unbound textbox on the form,
and in its Control Source put the equivalent of...
=Hex([YourNumberField])

--
Steve Schapel, Microsoft Access MVP

I also have a 11 digit numerical field on a form. I have a second field on my
form, where I would like to take the numeric number in that first field, and
populate this second field with the hexadecimal equivilent. Is there any
programming that anyone knows of that can do this?

Thanks again,

Richard
 
Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))
 
thanks Steve. I tried it both ways and all I get is a "#Num!" regardless. I
appreciate the help. I actually can get the Hex number, but I wanted to try
and find a lazy way instead <G>.

Richard

Steve Schapel said:
Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))

--
Steve Schapel, Microsoft Access MVP
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?
 
Richard

This is a lazy way :-) There is something I'm missing here. I have
tried it myself now, based on the information you have given so far, and
it works fine for me. Can you give some examples of the data?
 
Richard,

Here's a thought... what is the name of the unbound textbox where you
are entering the expression in the control source? This control can not
be named the same as a field in the form's record source, or you will
get an error.
 
Depending on the version of Access, you can get an overflow error on an
11-character number.

The largest decimal value I could handle in Access 97 was
Hex(2147483647)
thanks Steve. I tried it both ways and all I get is a "#Num!" regardless. I
appreciate the help. I actually can get the Hex number, but I wanted to try
and find a lazy way instead <G>.

Richard

Steve Schapel said:
Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))

--
Steve Schapel, Microsoft Access MVP
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?
 
Good point, John. I must confess I only tested with smaller numbers
before replying to Richard before. It now appears your 2147483647 limit
also applies to later versions of Access as well, including Access 2003.
 
I'll try a couple of suggestions. A typical number I am trying to convert is
an 11 digit decimal number, like 07234502134 or 06701340872. So, maybe I
cannot even do this since I am using such a large number.
 
You are right on the nose. The numbers I am trying to convert are too large.
Oh well, thanks for all the help guys. Much appreciated!!

John Spencer (MVP) said:
Depending on the version of Access, you can get an overflow error on an
11-character number.

The largest decimal value I could handle in Access 97 was
Hex(2147483647)
thanks Steve. I tried it both ways and all I get is a "#Num!" regardless. I
appreciate the help. I actually can get the Hex number, but I wanted to try
and find a lazy way instead <G>.

Richard

Steve Schapel said:
Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))

--
Steve Schapel, Microsoft Access MVP

Richard wrote:
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?
 
They're not too large: they're just too large to use the built-in Hex
function.

However, you'd have to write your own math routines to deal with the
conversion, since if you convert them to Single or Double values, you'll
lose precision in your answer.

Unfortunately, a quick search just now didn't result in any useful code that
I could post to show you the techniques.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Richard said:
You are right on the nose. The numbers I am trying to convert are too large.
Oh well, thanks for all the help guys. Much appreciated!!

John Spencer (MVP) said:
Depending on the version of Access, you can get an overflow error on an
11-character number.

The largest decimal value I could handle in Access 97 was
Hex(2147483647)
thanks Steve. I tried it both ways and all I get is a "#Num!" regardless. I
appreciate the help. I actually can get the Hex number, but I wanted to try
and find a lazy way instead <G>.

Richard

:

Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))

--
Steve Schapel, Microsoft Access MVP

Richard wrote:
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?
 
Thanks Doug. I'll keep on searching, because Im definately not a code writer
:-)

Richard

Douglas J. Steele said:
They're not too large: they're just too large to use the built-in Hex
function.

However, you'd have to write your own math routines to deal with the
conversion, since if you convert them to Single or Double values, you'll
lose precision in your answer.

Unfortunately, a quick search just now didn't result in any useful code that
I could post to show you the techniques.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Richard said:
You are right on the nose. The numbers I am trying to convert are too large.
Oh well, thanks for all the help guys. Much appreciated!!

John Spencer (MVP) said:
Depending on the version of Access, you can get an overflow error on an
11-character number.

The largest decimal value I could handle in Access 97 was
Hex(2147483647)

Richard wrote:

thanks Steve. I tried it both ways and all I get is a "#Num!" regardless. I
appreciate the help. I actually can get the Hex number, but I wanted to try
and find a lazy way instead <G>.

Richard

:

Richard,

Why not give it a try? I am pretty sure it will work even if it is a
text field. But if not, try this...
=Hex(Val([YourNumberField]))

--
Steve Schapel, Microsoft Access MVP

Richard wrote:
Steve,

One other thing I should have mentioned, is that the 11 digit field I have
was originally set up as a text field. Does this mean your solution will not
work?
 
Richard said:
I'll try a couple of suggestions. A typical number I am trying to convert is
an 11 digit decimal number, like 07234502134 or 06701340872. So, maybe I
cannot even do this since I am using such a large number.

The argument for Hex seems to be limited to a Long integer
and your 11 character string of digits is bigger than a Long
can hold.

Here's a function that should be able to deal with a string
of up to about 17 digits:

Public Function BigHex(K) As String
Dim lngHigh As Long
Dim lngLow As Long
lngHigh = Fix(CDec(K) / CDec(2 ^ 28))
lngLow = CDec(K) - CDec(lngHigh * 2 ^ 28)
BigHex = Hex(lngHigh) & Right("0000000" & Hex(lngLow), 7)
End Function
 
Where does this code go exactly?

Marshall Barton said:
The argument for Hex seems to be limited to a Long integer
and your 11 character string of digits is bigger than a Long
can hold.

Here's a function that should be able to deal with a string
of up to about 17 digits:

Public Function BigHex(K) As String
Dim lngHigh As Long
Dim lngLow As Long
lngHigh = Fix(CDec(K) / CDec(2 ^ 28))
lngLow = CDec(K) - CDec(lngHigh * 2 ^ 28)
BigHex = Hex(lngHigh) & Right("0000000" & Hex(lngLow), 7)
End Function
 
Richard said:
Where does this code go exactly?

In a standard module.

Click the Modules tab in the database window. Select New
and copy/past in the code.
--
Marsh
MVP [MS Access]

 
Back
Top