Page 1 of 1
calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 2:42 pm
by chris25
Just a push in the right direction please: This is a simple conversion app - - the empty button is the 'Go" button
All the calculations involve the first drop down menu having the number '1'. So please just tell me if I have started correctly as far as the flow in the right direction is concerned, if I have I think I know where to go from here…otherwise please could you show me the first signpost.
Yes I did the exercise with the pink elephant in the tutorial

and a runrev search did not reveal much that I could find.
Thankyou
chris
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 3:03 pm
by Klaus
Hi Chris,
since all menu items "resolve" to the same value -> 1, no need to check the chosen menu items at all:
Code: Select all
global firstinteger
on menupick
put 1 into firstinteger
end menupick
Hope I understood you right
Best
Klaus
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 3:52 pm
by chris25
Yes ok then thanks. The second set will naturally have different numerical values.
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 3:56 pm
by Klaus
Ah, I see. And yes, the original syntax is correct!
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 4:15 pm
by chris25
Ah, now you're lost me.
The first dropdown menu has the code that you suggested. I deleted all the switch a case words. the second drop down menu has different entries for each word in the list, so the syntax looks more or less as the one posted above with the case and switch words included.
Ok this is wrong obviously. The two variable represent the two integer values that I have already established. But these two variables will be divided or multiplied together and their value will then be multiplied by the user's input in the far left hand box. in other words let us say that the two variables amount to 1x0.353; the user has typed in 5; so the final calculation needs to be represented as : 5 x (1 x 0.353).
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 5:03 pm
by Klaus
That is correct

Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 8:02 pm
by chris25
How is this correct Klaus? Unless we cross-posted
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 8:06 pm
by Klaus
Hi Chris,
sorry, I meant your second paragraph:
The first dropdown menu has the code that you suggested. I deleted all the switch a case words. the second drop down menu has different entries for each word in the list, so the syntax looks more or less as the one posted above with the case and switch words included.
Regarding your problem:
You forgot to declare the globals used in the script!
Best
Klaus
Re: calculation exercise with drop down down menu
Posted: Sun Nov 03, 2013 8:35 pm
by chris25
That was an annoying mistake. Ok Klaus thankyou. I have succeeded in this all by myself now, but I have one problem that I can not work out, and this will complete the little exercise. Like an idiot I forgot that while the first drop down menu is always a '1', the second drop down menu has integers corresponding to the item chosen. But some of these two drop down menus need to be multiplied with each other and some need division according to the combination chosen. For example:
If ounces and grams are chosen then it would be 1/0.0353
if grams and ounces are chosen then it would be 1*0.0353
I know I could easily arrange the maths so that ALL calculations are either multiplication or division, but that is making it too easy for me, I need to be able to solve it this way because the maths world is not always this convenient.
My idea is to put a series of if and then statements throughout here in this script below. I have read that each 'case' is in fact a separate handler for that item. Is this the way to go?
case "ounces"
put 0.035 into gsecondinteger
break
case "grams"
put 0.35 into gsecondinteger
edit: ok, this last silly idea will not work. I need to put the two statements into the go button but figure out a way to differentiate the two situations where sometimes the same integers need multiplying and sometimes they will need dividing depending upon which of the combinations are chosen by the user.....head scratching time...I need to refer back to the combinations and so I guess put If and Then conditions which point to the 'Items' in that drop down menu in their two different states....coffee time and head scratching
Ok I have a solution I think: three of the nine combinations need to be divided, the other six multiplied. Is their a way to group this kind of selection into its own variable, to take the two drop down menu choices and make it into one variable, or should I be looking at writing a custom function, which I would like to learn. So for eaxple when the user picks a group that need to be divided then this information is "called" and added to the variable ...hey, I'm making this up as I go along....the logic is there I think? Mmmm
