Page 1 of 1

Math operations on variables stored into another variable

Posted: Sat May 18, 2013 6:26 pm
by binah2102BUSABCX
Hi everybody, I hate to bother people in forums with obvious things, but what seem simple in LUA is is driving me crazy in LiveCode and it must be my error at the end.
What I am trying is to do math operations on variables and PUT or store them into another variable for later displaying like

put text of field "a" into varA
put text of field "b" into varB
put (varA * varB) / 568 into varC

but varB or field "b" is either an option menu or pull down menu or radio btn and it does not do the math. it always says error in right operand.
Can anyone help me please?
P.S tried with VALUE as stated in another post but still no luck.

Re: Math operations on variables stored into another variabl

Posted: Sat May 18, 2013 6:46 pm
by magice
You need to create a simple script in the drop down applying the choice value to an actual value. something like this

on menuPick pItemName
switch pItemName
case "1"
set the cValue of me to "1"
break
case "2"
set the cValue of me to "2"
break
case "3"
set the cValue of me to "3"
break
end switch
end menuPick

In this example you would also need to create a custom property of the dropdown cValue

Now just reference the cValue of button "dropdownName"

Re: Math operations on variables stored into another variabl

Posted: Sat May 18, 2013 6:55 pm
by binah2102BUSABCX
Thanks will give it a try now and post the result.

Re: Math operations on variables stored into another variabl

Posted: Sat May 18, 2013 7:22 pm
by sturgis
with an option button you can also use the label property to grab the text that is displayed on the button.


You could change your code to: put the label of button "yourOptionButt" into varB

For radio buttons (that are grouped)

you can do something like: put the label of button (the hilitedbutton of group "groupname") of group "groupname" into varB. Though you need to make sure and check that "the hilitedbutton" is not 0 (no radio button selected) so put "if the hilitedbutton of group "groupname" is not 0 then...

With the drop down menu you must do as indicated and use menupick to set a property that you can reference later.

Re: Math operations on variables stored into another variabl

Posted: Sat May 18, 2013 7:42 pm
by binah2102BUSABCX
Many Many Thanks Sturgis, will check all your suggestions.