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.
Math operations on variables stored into another variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 3
- Joined: Wed Aug 15, 2012 5:10 pm
Re: Math operations on variables stored into another variabl
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"
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"
-
- Posts: 3
- Joined: Wed Aug 15, 2012 5:10 pm
Re: Math operations on variables stored into another variabl
Thanks will give it a try now and post the result.
Re: Math operations on variables stored into another variabl
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.
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.
-
- Posts: 3
- Joined: Wed Aug 15, 2012 5:10 pm
Re: Math operations on variables stored into another variabl
Many Many Thanks Sturgis, will check all your suggestions.