Page 1 of 1

Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 1:56 am
by haer
Hi all, im new to livecode.

How do i return a value to a field when 2 choices are chosen from 2 separate menupicks?

say A and B is chosen from 2 menupicks, and the field would show a value "3".

Thanks in advance.

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 2:15 am
by Simon
Hi haer,
Welcome to the forums :)

Which type of menu are you using (eg pulldown, popup, combo box)?
And do you really mean they pick "A" or do they pick a number?

Simon

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 2:23 am
by haer
Hi Simon,

thanks for the welcome.

im using the the option type of menu.

for eg. im having these 2 option type menu. i have 2 different combinations to choose. after choosing the 2 combinations, a field will return a result based on the 2 combinations.

Haer

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 2:40 am
by Simon
Hi Haer,
Yes, I understand what you want to happen except for if you want a number to be put into a field or "Choice 1 Choice 2" ?

Do you want the Menu Items to show up in the field or some processing of the Menu Items (eg value 1+2=3)?

Simon
Edited

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 4:22 am
by haer
Hi Simon,

for the field its gonna be a number value,

Choice 1 and Choice 2 would be a number or geometry code.

Im doing like somesort of lookup thing. currently working on a pipe geometry.

say i select a certain diameter of the pipe (ie. 508) and certain schedule of a pipe (ie. STD), it then gives me the corresponding pipe thickness (ie. 0.375) in the field.

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 4:55 am
by Simon
Hi Haer,
Ok Now we're getting there.
I'm not sure of the math behind STD so I'll fake it here

Code: Select all

 --First Option Menu
global gNum,gNum2
on menuPick pItemName
   switch pItemName
      case "OD 457.20"
         put 457.2 into gNum
         break
      case "OD 508.00"
         put 508.00 into gNum
         break
      case "OD 558.80"
         put 558.80 into gNum
         break
   end switch
   if gNum2 <> empty then
      put gNum / gNum2 into fld 1--BAD MATH
   end if
end menuPick
--Second Option Menu
global gNum,gNum2
on menuPick pItemName 
   switch pItemName
      case "SCH 20"
         put 1354.66 into gNum2
         break
         case "SCH 30"
         put 1016 into gNum2
         break
         case "SCH 40s/STD"
         put 1354.66 into gNum2
         break
   end switch
      if gNum <> empty then
      put gNum / gNum2 into fld 1--BAD MATH
   end if
end menuPick
Using this you'll find only OD 508 and SCH 30 come out correctly the true math is up to you.

Does this make sense? Ask more questions if you like.

Simon

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 11:16 am
by splash21
Greetings, Haer - you can also try putting 2 option menus on a card and a field (mine are called ChoiceA, ChoiceB and Data). Group the option menus by selecting both of them then pressing the 'Group' button on the LiveCode toolbar. Now put the following code into the new group object that contains the options;

Code: Select all

on menuPick pItem
   local tChoiceA, tChoiceB
   
   put the label of button "ChoiceA" into tChoiceA
   put the label of button "ChoiceB" into tChoiceB
   
   # now you can validate / calcuate / lookup data for the field or do whatever else you need to do with the 2 variables 'tChoiceA' and 'tChoiceB'
   # I'll just show them in the Data field
   put tChoiceA & " / " & tChoiceB into field "Data"
end menuPick
You can do whatever you need with the tChoiceA and tChoiceB variables - the code will run when either of the menus changes.

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 12:13 pm
by Klaus
Hi haer,

1. welcome to the forum :D

2. Please check these stacks to get the basics of Livecode (including menus)
http://www.hyperactivesw.com/revscriptc ... ences.html

Maybe start with stack "Controls" 8)


Best

Klaus

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 10:38 pm
by Simon
I've been thinking about this...
The industry is very old and there may not be a mathematical equation between the two (I mean you could make one but it would be one for each possibility) but they rely on lookup tables.

Is that true Haer?
Don't worry the worst part is just manually loading the variables.

Simon

Re: Return Value based on Choices from 2 Menupicks

Posted: Mon Dec 23, 2013 11:46 pm
by dunbarx
These will have to be drawn from a look-up table of some sort. In the U.S., (ASTM, or NPS/T) there is a general rule about pipe diameters as opposed to their "trade" size, that is, the trade size O.D. is about 1/4" smaller than the actual value. A 1/8" trade is about 3/8" in reality. And that depends on the schedule. Anyway, the rule is not precise, and does not hold as the diameters get larger, so no calculation will do. Other countries have different standards as well.

Craig

Re: Return Value based on Choices from 2 Menupicks

Posted: Tue Dec 24, 2013 6:21 am
by haer
Hi all,

thanks for all the responses. like what was mentioned there is no mathematical calculation relation between the 2 variables, im just using it as a lookup variable to return the corresponding wall thickness based on the existing standard table.

anyways managed to solved it after reading your responses and some helpful links.

thanks guys.

haer

Re: Return Value based on Choices from 2 Menupicks

Posted: Fri Dec 27, 2013 5:23 pm
by Daross
Hi haer,
if I understand correctly, you have to create 2 drop down buttons and from which to create a block of text and then search a value in a list of data:
1. drag a drop-down button and call it "pipeType"
  Populate menu items with "Pipe 1 inch" and "Pipe 2 inch"
2. drag a drop-down button and call it "pipeOption"
  Populate menu items with "STD" and "Special"
3. drag a field and call it "ticknessPipe"
4. Create a table field, and call it "pipedata"
populate its contents with this text:
+---------------------+-----+
| Pipe 1 inch STD | 0.1|
+---------------------+-----+
| Pipe 1 inch Special | 0.2|
+---------------------+-----+
| Pipe 2 inch STD | 0.8|
+---------------------+-----+
| Pipe 2 inch Special | 1.0|
+---------------------+-----+
(item 1 is the description of pipe, item 2 is the tickness)
5. in the code of the card, paste this

Code: Select all

on searchPipeTickness
   
   put label of button "pipeType" && label of button "pipeOption" into varPipe
   put field "pipeData" into varPipeData
   
   set itemdel to TAB
   
   put item 2 of line (lineOffset (varPipe & Tab, varPipeData))  varPipeData  into  varPipeTickness
   
   put varPipeTickness into field "ticknessPipe"
   
end searchPipeTickness
6. in the code of the 2 drop down buttons paste this:

Code: Select all

on menuPick 
   searchPipeTickness
end menuPick
I hope it works