type conversions of values and variables?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

type conversions of values and variables?

paulhatherly
Hi,
I'm new to plua, so please forgive me if this is common knowledge.
I am trying to (arithmetically) compare a number with a string returned
from an input, and I get a "trying to compare a string with a number"
error (quite reasonably!)- I had hoped the values would be "coerced" to
be the same type.
How can I convert the returned string to a number, to allow the
comparison?
For information, the relevant line of code looks like:

if a>=b then.....
a is the returned string and b is a number.

I am using plua v. 2.0b4

Many thanks,
Paul Hatherly





------------------------ Yahoo! Groups Sponsor --------------------~-->
Protect your PC from spy ware with award winning anti spy technology. It's free.
http://us.click.yahoo.com/97bhrC/LGxNAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/plua/

<*> To unsubscribe from this group, send an email to:
    [hidden email]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply | Threaded
Open this post in threaded view
|

Re: type conversions of values and variables?

bh77a-2
Hi Paul,

Welcome to the world of Plua.  Hope you enjoy it.

To answer your question (hopefully), try something along the lines of:

--SToI should be the numerical value of string A
--tonumber(...,...) is a standard Lua 5 function
--a second argument can be supplied, to dictate the base that the number
should be returned as
--a base of 10 should return a decimal or exponential notation
--any other base between 2 and 36
SToI=tonumber(A)
if SToI >= B then
...
...
end

Please note that I haven't tried it as I am away for a bit, but it should
work.

Brian

> Hi,
> I'm new to plua, so please forgive me if this is common knowledge.
> I am trying to (arithmetically) compare a number with a string returned
> from an input, and I get a "trying to compare a string with a number"
> error (quite reasonably!)- I had hoped the values would be "coerced" to
> be the same type.
> How can I convert the returned string to a number, to allow the
> comparison?
> For information, the relevant line of code looks like:
>
> if a>=b then.....
> a is the returned string and b is a number.
>
> I am using plua v. 2.0b4
>
> Many thanks,
> Paul Hatherly
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>




------------------------ Yahoo! Groups Sponsor --------------------~-->
Protect your PC from spy ware with award winning anti spy technology. It's free.
http://us.click.yahoo.com/97bhrC/LGxNAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/plua/

<*> To unsubscribe from this group, send an email to:
    [hidden email]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply | Threaded
Open this post in threaded view
|

Re: type conversions of values and variables?

paulhatherly
Hi Brian,
Yes, pretty good fun! Crashing my pda frequently as I'm
experimenting, but all my fault (not catching appStop events
properly, for example!)
A little background in Visual Basic is helping with the event-driven
philosophy of plua (at least, as I see it); I just need to learn the
commands and the more advanced syntax...
Many thanks for your help with the "tonumber(...)" command - I
confirm this works fine in plua!
Regards,
Paul Hatherly

--- In [hidden email], bh@... wrote:
>
> Hi Paul,
>
> Welcome to the world of Plua.  Hope you enjoy it.
>
> To answer your question (hopefully), try something along the lines
of:
>
> --SToI should be the numerical value of string A
> --tonumber(...,...) is a standard Lua 5 function
> --a second argument can be supplied, to dictate the base that the
number

> should be returned as
> --a base of 10 should return a decimal or exponential notation
> --any other base between 2 and 36
> SToI=tonumber(A)
> if SToI >= B then
> ...
> ...
> end
>
> Please note that I haven't tried it as I am away for a bit, but it
should
> work.
>
> Brian
>
> > Hi,
> > I'm new to plua, so please forgive me if this is common
knowledge.
> > I am trying to (arithmetically) compare a number with a string
returned
> > from an input, and I get a "trying to compare a string with a
number"
> > error (quite reasonably!)- I had hoped the values would
be "coerced" to

> > be the same type.
> > How can I convert the returned string to a number, to allow the
> > comparison?
> > For information, the relevant line of code looks like:
> >
> > if a>=b then.....
> > a is the returned string and b is a number.
> >
> > I am using plua v. 2.0b4
> >
> > Many thanks,
> > Paul Hatherly
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>






------------------------ Yahoo! Groups Sponsor --------------------~-->
Protect your PC from spy ware with award winning anti spy technology. It's free.
http://us.click.yahoo.com/97bhrC/LGxNAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/plua/

<*> To unsubscribe from this group, send an email to:
    [hidden email]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/