LCB: Complex statement help needed in LCB

Stephen MacLean smaclean at madmansoft.com
Tue Mar 1 16:14:32 EST 2016


> On Mar 1, 2016, at 3:58 PM, Peter TB Brett <peter.brett at livecode.com> wrote:
> 
> 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

Hi Peter,

Thanks:) Being strongly typed has it’s plusses and minuses. I was hoping to avoid “parsed as number” by using the “any” type.

It looks like that when you have a variable in LCB with a type of “any” and perform an action on it, it becomes that type. So perform “put the number of chars in tCardNum into tLen” and tCardNum becomes a string type. Do "put 0 into tCheckSum” and tCheckSum becomes a number.

I'll give it a go. While I could just wrap the whole thing up and execute it as a script, I’m really trying to do as much as possible in LCB to learn.

Thanks so much!

Best,

Steve MacLean




More information about the use-livecode mailing list