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

Rafa Domenech rafadose at ...626...
Fri Mar 26 10:06:26 CET 2010


Hello Benoît,
 You're right, I didn't know how to say that it was unsigned. So this code
now works fine:

  DIM test AS Integer

    test = Val("&H" & TextBox1.Text & "&")

Thankyou

Rafa


On 26 March 2010 06:10, Benoît Minisini <gambas at ...1...>wrote:

> > 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
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list