Please HELP:Hexadecimal conversion error????

Quote:

> > can this be true? (taken from my debug window):

> > ?print hex(sc_close)

> > F060

> > print sc_close

> > -4000

> > print hex(wptemp)

> > F060

> > print wptemp

> > 61536

> > How come the same value in Hex notation (&HF060) be a diferent value

> > in decimal notation?

> > sc_close is a public const and wptemp is a Long Var.

> > Can anybody please expalin this to me?

> The values are the same if counting with 16 bit integers. It seems that

> Public Const converts the value to the least integer that contains

> the value.

As Peter points out, VB automatically selects the smallest data type

that will hold the value. In this case it is Integer. But the Integer

data type is SIGNED. With a 16 bit data area, this means that

&H0000-&H7FFF is used for positive values, and &H8000-&HFFFF is used for

negative; hence, &HF060 returns -4000 in decimal.

The Long data type is also SIGNED, but is 32 bits wide. Hence, the

positive values are &H00000000-&H7FFFFFFF, and the negatives are

&H80000000-&HFFFFFFFF. So, &HF060 is interpreted as &H0000F060, which

is the positive value 61536.

I would suggest declaring the value for the constant in decimal

notation, rather than hex. That will force the data type to a Long.

(It may work to specify leading zeros, as well: &H0000F060)

Craig Warford

WAR