# VB6 and &H constants...



## tim8w (Nov 9, 2004)

Can anyone explain what the difference between the following statements is:

Dim lValue As Long

lValue = 65536 And &HFF00
lValue = 65536 And &HFF00&


For the first statement, lValue = 65536
For the second statement, lValue = 0

If I do the following:

lValue = 65536 And &HFF0000

VB works correctly (lValue=1) and it won't let me add the extra & on the end.

Why do I need the extra & on the end on Hex numbers that end in 0?

Thanks,
Tim


----------



## dquigley (Apr 17, 2006)

The & character placed after a numeric constant indicates it is a Long Integer type. 

The &H characters placed before a numeric constant, indicates the following characters are interpreted as Hex (Base16).

The difference between:

&HFF00 is hex FF00 a short (16bit) integer
&HFF00& is hex 0000FF00 a long (32bit) integer
&HFF0000 is hex 00FF0000 a long (32bit) integer
65536 is hex 00010000 is a long (32bit) remember the max value for a short integer is 65535 or (FFFF).

Therefore in your examples:

lValue = 65536 And &HFF00 is the same as lValue = &H00010000 And &HFF00
lValue will = 0 

lValue = 65536 And &HFF00& is the same as lValue = &H00010000 And &H0000FF00
lValue will = 0

lValue = 65536 And &HFF0000 is the same as lValue = &H00010000 And &H00FF0000
lValue will = 65536 or hex 00010000


----------

