Math operations on variables stored into another variable

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
binah2102BUSABCX
Posts: 3
Joined: Wed Aug 15, 2012 5:10 pm

Math operations on variables stored into another variable

Post by binah2102BUSABCX » Sat May 18, 2013 6:26 pm

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.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Math operations on variables stored into another variabl

Post by magice » Sat May 18, 2013 6:46 pm

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"

binah2102BUSABCX
Posts: 3
Joined: Wed Aug 15, 2012 5:10 pm

Re: Math operations on variables stored into another variabl

Post by binah2102BUSABCX » Sat May 18, 2013 6:55 pm

Thanks will give it a try now and post the result.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Math operations on variables stored into another variabl

Post by sturgis » Sat May 18, 2013 7:22 pm

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.

binah2102BUSABCX
Posts: 3
Joined: Wed Aug 15, 2012 5:10 pm

Re: Math operations on variables stored into another variabl

Post by binah2102BUSABCX » Sat May 18, 2013 7:42 pm

Many Many Thanks Sturgis, will check all your suggestions.

Post Reply