[Gambas-user] ¿bug? Error with Val function and hex values

Benoît Minisini gambas at ...1...
Fri Mar 26 06:10:11 CET 2010


> Hello,
> 
> I've a problem trying to convert a string in hex to decimal.
> When I do this:
> test = (Val("&H9000") AND 65535)
> I obtain
> test = -28672 (equals to 0xFFFFFFF9000)
> and it should be
> test = 36864 (0x9000)
> 

It depends: what is the full source code with the declaration of 'test'?

> And when I debug it step by step I obtain what you can see in this
> screenshot.
> [image: Pantallazo-1.png]
> This example seems very stupid (and it is), I did it because I noticed that
> this code
> test = Val("&H" & TextBox1.Text)
> didn't work fine with TextBox1.Text="9000" and maybe with other values.
> Then I tried to "cut" with AND with &HFFFFF but it didn't work so I
> changed it to its decimal conversion 65535 and now at least the debugger
> shows the correct value but it doesn't asign it to test.
> 
> I'm using Gambas 2.20.2  in Ubuntu 9.10 with 2.6.31-20-generic kernell
> 
> Thankyou
> 
> Rafa

&Hxxxx is a signed 16 bits integer. If you want an unsigned value, you must 
add a '&' at the end of the number: &Hxxxx&. That is a strange inheritance 
from VB.

In Gambas 3, the same principle was applied to 32 bits integer: &Hxxxxxxxx is 
a signed 32 bits integer, and if you need an unsigned one, you must use 
&Hxxxxxxxx&.

Regards,

-- 
Benoît Minisini




More information about the User mailing list