Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring HEX constants drives me wild 1

Status
Not open for further replies.

MickTheBelgian

Programmer
Jan 11, 2001
160
DK
in a module:
Public Const A As Long = &H8000
Public Const b As Long = &H1 Or A


run the app, press pause
in the immediate window:

?hex(b)
FFFF8001

bang head on desk very hard
 
You are "Or" - ing the A and B constants together which is a bitwise command therefore &H1 Or A is the same as &H1 Or &H8000 which is the same as &H8001. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
That is exactly what I hope for, but why does it come out as FFFF8001 in the software????
 
If you are refering to the FFFF 'prefix' on the 8001 it is because you have them declared as long, if you just want the 8001 declare the constants as Integer. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
Thanks! It does strike me as odd however,
Long or integer, &H8000 = &HFFFF8000 ????
I guess it is because VB doesn't know unsigned integers.
The API function expects a LONG and spits out a positive number, but the constant changes into a negative number.
Maybe I will need to have an integer and a long version of each constant...
 
Trying defining them as

Public Const A As Long = &H8000&
Public Const b As Long = &H1& Or A

(ampersand at end) this will force each value into a long when assigning it to the constant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top