calculation exercise with drop down down menu

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
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

calculation exercise with drop down down menu

Post by chris25 » Sun Nov 03, 2013 2:42 pm

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 :roll: and a runrev search did not reveal much that I could find.

Thankyou
chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calculation exercise with drop down down menu

Post by Klaus » Sun Nov 03, 2013 3:03 pm

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 :D

Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: calculation exercise with drop down down menu

Post by chris25 » Sun Nov 03, 2013 3:52 pm

Yes ok then thanks. The second set will naturally have different numerical values.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calculation exercise with drop down down menu

Post by Klaus » Sun Nov 03, 2013 3:56 pm

Ah, I see. And yes, the original syntax is correct!

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: calculation exercise with drop down down menu

Post by chris25 » Sun Nov 03, 2013 4:15 pm

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).

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calculation exercise with drop down down menu

Post by Klaus » Sun Nov 03, 2013 5:03 pm

That is correct :D

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: calculation exercise with drop down down menu

Post by chris25 » Sun Nov 03, 2013 8:02 pm

How is this correct Klaus? Unless we cross-posted

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calculation exercise with drop down down menu

Post by Klaus » Sun Nov 03, 2013 8:06 pm

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! 8)


Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: calculation exercise with drop down down menu

Post by chris25 » Sun Nov 03, 2013 8:35 pm

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 :?

Post Reply