LCB: Complex statement help needed in LCB

Peter TB Brett peter.brett at livecode.com
Tue Mar 1 15:58:35 EST 2016


On 01/03/2016 20:44, Stephen MacLean wrote:
> Hi All,
>
> I’m looking for some help on complex statements in LCB.
>
> I’m trying to take a script statement like this:
>
> if (char x of tCardNum)*2 > 9 then

Hi Stephen,

Don't forget that LCB is strongly typed.  That means that a string isn't 
a number, so you can't multiply it!

The expression "char x of tCardNum" evaluates to a string that's one 
character long.  If "tCardNum" has fewer than "x" characters, then it 
throws an error.

If the character is expected to be the string representation of a 
number, then you probably want to explicitly convert it to a number:

    variable tNum as Number
    put (char x of tCardNum) parsed as number into tNum
    if 9 < 2 * tNum then
       ...
    end if

                                            Peter


-- 
Dr Peter Brett <peter.brett at livecode.com>
LiveCode Open Source Team

LiveCode 2016 Conference https://livecode.com/edinburgh-2016/




More information about the use-livecode mailing list