Conversion issues In VBA Excel- Why HFFF is giving -1 in long and how to resolve it

StackOverflow https://stackoverflow.com/questions/17780120

  •  03-06-2022
  •  | 
  •  

Pregunta

I am using VB in excel and creating a macro for CRC16 bit calculation. When I take values from the lookup table above 8000 to FFFF, they are giving negative numbers. I then got to know that numbers below this range will be positive and numbers in this range(8000-FFFF) will give a negative result which has to be converted. I came across a few functions like these but they dont solve my purpose

Is it possible to do the conversion using a simple function so that I can get the correct result.

HFFFF gives -1 to a long variable but I want 65535.

I have used the functions given here http://support.microsoft.com/kb/161304 but it does not give me the correct result when i pass a hex value like HFFFF.

¿Fue útil?

Solución

Hexadecimal constants are signed. This is actually described in the VBA spec: http://msdn.microsoft.com/en-us/library/ee199514.aspx

There are two ways around this issue:

1) use the literal decimal

2) use an ampersand type hint like &HFFFF&

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top