How do you get hex zeros and hex FF into a variable

T

Tony Girgenti

How do you get hex zero or hex 'FF' into a variable ?

I tried:
If Hex(255) < "Z" Then
MsgBox "Hex(255) is less than 'Z'"
End If

and the message box does appear.
Shouldn't "Hex(255)" equate to a &FF ?

Any help appreciated.

Thanks,
Tony
 
L

Larry Linson

What are you trying to accomplish?

The Hex built-in function returns a _string_ showing the specified number in
a hexadecimal representation. That doesn't appear to be what you want to do.

What type of variable do you want to set to all one-bits or all-zero bits?

Here's a small function to illustrate setting a numeric variable to a number
expressed in hex:

Public Function conver() As Long
conver= &HFF
End Function

You can execute it from the Debug/Immediate window with ? conver(), if you
copy and paste it into a standard module.

Larry Linson
Microsoft Access MVP
 
A

Allen Browne

What kind of variable?

If it's a Byte, these would be equivalent:
MyByte = 255
MyByte = &HFF

Or did you actually want a String variable:
MyString = "&H" & Hex(255)
and then:
? Val(MyString)
 
G

Graham Mandeno

Hi Tony

The Hex function simply converts a numeric argument into its hexadecimal
representation *as a string*

Hex(255) gives "FF", which is indeed less than "Z", because "F" comes before
"Z" in the alphabet.

I think what you want is the Chr( ) function, which returns the character
corresponding to the given ACSII character code.

Chr(89) < "Z" gives True, because "Y" is less than "Z"

However:
Chr(97) < "Z" also gives True, because "a" is less than "Z" in the normal
collating sequence.

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
T

Tony Girgenti

Thanks to all that replied.

I'm an old COBOL programmer and we used terms like LOW-VALUES and
HIGH-VALUES to represent binary zeros and hex FF respectively.

All i'm trying to do is fill a string variable with either one of those.

Thanks,
Tony
 
L

Larry Linson

Dim strLowValues as String
Dim strHighValues as String
strLowValues = Chr$(0)
strHighValues = Chr$(255)

But, er, you have to be careful about "character" these days, since a
character may well be unicode and occupy two bytes.

If you want a single-byte numeric variable containing binary zeroes:

Dim bytLow as Byte
Dim bytHigh as Byte
bytLow = &H0
bytHigh = &HFF

Thus, my question about how you want to _use_ the values you want to
generate.

In a previous incarnation as a mainframer, I did some COBOL and PL/1 and a
number of others. But, I'm still in the dark about how I'd use a Chr$(0) in
Access except to terminate a string that I was passing to the API or to a
function done in C which required a "null-terminated string", and am
completely puzzled about why I'd use the "FF", unless I were doing logic on
Boolean values/masks.

Larry Linson
Microsoft Access MVP
 
T

Tony Girgenti

Larry,

I have a form that allows a user to input a starting item number and an
ending item number. They have check boxes next to the input fields to
indicate "First" and "Last". So if they check the box next to starting
item, i want to fill the starting item variable with the lowest possible
value for selecting inventory records for a report. The same for the ending
item, except i want the highest possible value.

Hope this help to explain what i am trying to accomplish.

Any other ideas ?

Thanks,
Tony
 

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