MultiChoice Combo Boxes..?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
MultiChoice Combo Boxes..?
Hi,
I hope this hasn't been coverd, (I have looked), so I hope someone can help...
I have sucessfully designed my GUI but am struggerling with the back end code. If I explain what it is I am trying to achieve then maybe someone could point me in the right direction...
I have three combo boxes, each one has three user choices, depending on which one the user choose creates a differnt outcome, of which there are 27. I have created the combo boxes and the choices, I just need to know how to give it a list to choose from and output the answer..?
Thanks in advance,
I hope this hasn't been coverd, (I have looked), so I hope someone can help...
I have sucessfully designed my GUI but am struggerling with the back end code. If I explain what it is I am trying to achieve then maybe someone could point me in the right direction...
I have three combo boxes, each one has three user choices, depending on which one the user choose creates a differnt outcome, of which there are 27. I have created the combo boxes and the choices, I just need to know how to give it a list to choose from and output the answer..?
Thanks in advance,
Re: MultiChoice Combo Boxes..?
I am guessing that you are going to have a button to start the process rather than have it be something that changes when the menu items are picked individually in which case there are quite a few ways do do what you want.
First, look up menuhistory in your dictionary. You can get the line number of the current choice for each of your combo boxes this way, and with your 3 lines per box scenario, you can check each combo box for its current value and then can use the responses to find the correct data you want back.
Either you can have your possible responses be in a field in the form of "121,the response text" and use lineoffset to find the correct line (could be held in a variable also which would be faster anyway) then grab item 2 from the line number returned by lineoffset.
Another way would be to use an array to store your responses. If you setup an array theDataA[thekey] where the keys are the possible combinations of your fields (IE, an entry in theDataA[111], another in theDataA[112] etc) then you can just pop out the correct information based on the menuhistory of your comboboxes.
Another way would be to treat your combo boxes as a trinary numbering system and setup a function that converts to a decimal number that can be used to grab a specific line out of a field or variable. Silly to do so, but not too difficult overall.
First, look up menuhistory in your dictionary. You can get the line number of the current choice for each of your combo boxes this way, and with your 3 lines per box scenario, you can check each combo box for its current value and then can use the responses to find the correct data you want back.
Either you can have your possible responses be in a field in the form of "121,the response text" and use lineoffset to find the correct line (could be held in a variable also which would be faster anyway) then grab item 2 from the line number returned by lineoffset.
Another way would be to use an array to store your responses. If you setup an array theDataA[thekey] where the keys are the possible combinations of your fields (IE, an entry in theDataA[111], another in theDataA[112] etc) then you can just pop out the correct information based on the menuhistory of your comboboxes.
Another way would be to treat your combo boxes as a trinary numbering system and setup a function that converts to a decimal number that can be used to grab a specific line out of a field or variable. Silly to do so, but not too difficult overall.
Re: MultiChoice Combo Boxes..?
Yes I was actually hopeing to change the output as and when the menu's change, is this possible..?
Cheers.
Cheers.
Re: MultiChoice Combo Boxes..?
Dear topcat888,
Btw, a "user choice" in a combo box is called a (menu) item. It looks like you have 3 comboboxes with each 3 items. What is the problem you are having?
Best,
Mark
Could you please explain this in detail?I just need to know how to give it a list to choose from and output the answer..?
Btw, a "user choice" in a combo box is called a (menu) item. It looks like you have 3 comboboxes with each 3 items. What is the problem you are having?
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: MultiChoice Combo Boxes..?
Hi Mark
I think that what I need is an array which I populate with the fixed data to call depending on the out come of the three menu choices... Could I use a list of constants in this instance as they will not change or not..?
What sturgis suggested I use is menuHistory to see what the buttons picked result was but that would mean having a button, what I was hoping for is when you change one of the menu choices the output automatically changes without having the button at all... If its not possible, then I will stick with the button no problem..? Do I have to place a menuPick handler in each of the menu's..??
Also, can you give me a bit more guidance on the actual code to use, basically to say if menu A is on 1, menu B on 2 and menu C is on 1 get data line 121 from the array (or constant list) and put into field "output"..??
Thanks
I think that what I need is an array which I populate with the fixed data to call depending on the out come of the three menu choices... Could I use a list of constants in this instance as they will not change or not..?
What sturgis suggested I use is menuHistory to see what the buttons picked result was but that would mean having a button, what I was hoping for is when you change one of the menu choices the output automatically changes without having the button at all... If its not possible, then I will stick with the button no problem..? Do I have to place a menuPick handler in each of the menu's..??
Also, can you give me a bit more guidance on the actual code to use, basically to say if menu A is on 1, menu B on 2 and menu C is on 1 get data line 121 from the array (or constant list) and put into field "output"..??
Thanks
Last edited by topcat888 on Sun Jan 03, 2010 10:20 pm, edited 1 time in total.
Re: MultiChoice Combo Boxes..?
If you have the revweb plugin could you check http://runthenumbersnow.com/test.html and see if it is similar to what you're trying to do? Upper box has the strings to return, lower box returns the appropriate string based on whats chosen in the combo boxes.
If you don't have the revweb plugin yet you can get it at http://revweb.runrev.com/
Edit: Interesting, the combo box display doesn't update on pick in the revlet but still finds the correct line entries. Works fine in standalone. Is this a bug?
If you don't have the revweb plugin yet you can get it at http://revweb.runrev.com/
Edit: Interesting, the combo box display doesn't update on pick in the revlet but still finds the correct line entries. Works fine in standalone. Is this a bug?
Re: MultiChoice Combo Boxes..?
Hi sturgis, yes that's exactly what I'm trying to achieve, the only difference is I would like it to populate a text box with the answer only but yes...
Re: MultiChoice Combo Boxes..?
you can use the menuPick handler to do things live without needing an extra button as in the revlet I posted, t which you can either check based on the menuHistory or theItem to determine what to show. The only reason I showed the box containing the strings to show in the revlet is so you could see how I was setting up the data. (Ignore the weird bug that doesn't show changed menu choice in the revlet).
I do think it would be simpler to set it up as an array so that you don't have to mess with lineoffset.
You could have something like this:
I do think it would be simpler to set it up as an array so that you don't have to mess with lineoffset.
You could have something like this:
Code: Select all
put the menuHistory of button "combo1" & the menuHistory of button "combo2" & the menuHistory of button "combo3" into theIndex
put theArray[theIndex] into field "yourField"
topcat888 wrote:Hi Mark
I think that what I need is an array which I populate with the fixed data to call depending on the out come of the three menu choices... Could I use a list of constants in this instance as they will not change or not..?
What sturgis suggested I use is menuHistory to see what the buttons picked result was but that would mean having a button, what I was hoping for is when you change one of the menu choices the output automatically changes without having the button at all... If its not possible, then I will stick with the button no problem..? Do I have to place a menuPick handler in each of the menu's..??
Also, can you give me a bit more guidance on the actual code to use, basically to say if menu A is on 1, menu B on 2 and menu C is on 1 get data line 121 from the array (or constant list) and put into field "output"..??
Thanks
Re: MultiChoice Combo Boxes..?
Hi sturgis,
Your revlet doesn't have an extra button..??
ok, I think I'm still missing something here, this is what I've got so far (which does not return anything to the output box)... To make it simpler for the moment I have kept it to two menu's... plus those are the only conbinations that will be entered via those two menu's...
To explain the numbers in the array are as follows; put "1,2" is the first number choice from menu1, the second number choice from menu2; then the, into the Index["3,1"] is the answer that I want displayed in the output box..? Is that correct..?
put "1,2" into theIndex["3,1"]
put "1,3" into theIndex["2,1"]
put "2,1" into theIndex["3,2"]
put "2,3" into theIndex["1,2"]
put "3,1" into theIndex["2,3"]
put "3,2" into theIndex["1,3"]
put the menuHistory of button "menu1" & the menuHistory of button "menu2" into theIndex
put theArray[theIndex] into field "output"
Thanks
Your revlet doesn't have an extra button..??
ok, I think I'm still missing something here, this is what I've got so far (which does not return anything to the output box)... To make it simpler for the moment I have kept it to two menu's... plus those are the only conbinations that will be entered via those two menu's...
To explain the numbers in the array are as follows; put "1,2" is the first number choice from menu1, the second number choice from menu2; then the, into the Index["3,1"] is the answer that I want displayed in the output box..? Is that correct..?
put "1,2" into theIndex["3,1"]
put "1,3" into theIndex["2,1"]
put "2,1" into theIndex["3,2"]
put "2,3" into theIndex["1,2"]
put "3,1" into theIndex["2,3"]
put "3,2" into theIndex["1,3"]
put the menuHistory of button "menu1" & the menuHistory of button "menu2" into theIndex
put theArray[theIndex] into field "output"
Thanks
Re: MultiChoice Combo Boxes..?
Ok, I changed things to be closer to how you are looking at things. You can download a sample stack here http://runthenumbersnow.com/comboboxtest/
The stack itself is just 3 combo boxes, and an output field. The combo boxes are grouped and the group is named selectionGroup.
The code in that group is thus:
As mark asked earlier, if this is NOT how you intend things to work let us know.
The stack itself is just 3 combo boxes, and an output field. The combo boxes are grouped and the group is named selectionGroup.
The code in that group is thus:
Code: Select all
local theArray -- set theArray as a script local variable so all handlers in this script can see it.
on menuPick pThePick -- this fires when one of the combo boxes is changed.
-- make sure theArray is not empty,
--if it is fill it (with just sample data at this time of course)
if theArray is empty then
setupArray
end if
put the menuHistory of button "combo1" & comma & the menuHistory of button "combo2" & comma & the menuHistory of button "combo3" into theIndex
-- generate an index to key by that is in the same format as the keys used by the index.
put theArray[theIndex] into field "outField" -- put the keyed entry into the output field
end menuPick
-- this is the command to fill the array with sample data. Since each combo box has 3 items and there are 3 combo boxes
-- the nested repeat loop fills it up nicely and uses the same key format as above. The menuHistory numbers seperated by comma.
command setupArray
repeat with i = 1 to 3
repeat with n = 1 to 3
repeat with x = 1 to 3
put i & comma & n & comma & x into theIndex
put "This is what you get if you choose " & theIndex && " for the 3 combo boxes" into theArray[theIndex]
end repeat
end repeat
end repeat
end setupArray
Re: MultiChoice Combo Boxes..?
Hi sturgis,
All perfect apart from the fact that I don't think I have explained myself properly (unless I'm missing something) ~ When the three combo's are picked those three numbers can't be seen, it is the numbers that diectly relate to a specific combination that need to be shown in outField, the ones that should be stored as fixed data in the array..?
Hence why I had this list (only for two combo's but the principals the same):
put "1,2" into theIndex["3,1"]
put "1,3" into theIndex["2,1"]
put "2,1" into theIndex["3,2"]
put "2,3" into theIndex["1,2"]
put "3,1" into theIndex["2,3"]
put "3,2" into theIndex["1,3"]
In other words for example when combo1 is picked at choice 1and combo2 is picked at choice 2 then the answer that should be shown in outField is: 3,1
Also, the number choice on the all the combo's needs to be 1 2 3 not 31,32 etc
Plus, if the user is viewing this app with internet explorer is it possible to fix the window size to the actual size of the app..??
Thanks for your time,
All perfect apart from the fact that I don't think I have explained myself properly (unless I'm missing something) ~ When the three combo's are picked those three numbers can't be seen, it is the numbers that diectly relate to a specific combination that need to be shown in outField, the ones that should be stored as fixed data in the array..?
Hence why I had this list (only for two combo's but the principals the same):
put "1,2" into theIndex["3,1"]
put "1,3" into theIndex["2,1"]
put "2,1" into theIndex["3,2"]
put "2,3" into theIndex["1,2"]
put "3,1" into theIndex["2,3"]
put "3,2" into theIndex["1,3"]
In other words for example when combo1 is picked at choice 1and combo2 is picked at choice 2 then the answer that should be shown in outField is: 3,1
Also, the number choice on the all the combo's needs to be 1 2 3 not 31,32 etc
Plus, if the user is viewing this app with internet explorer is it possible to fix the window size to the actual size of the app..??
Thanks for your time,
- Attachments
-
- comboBoxTestRev2.rar
- (2.36 KiB) Downloaded 243 times
Re: MultiChoice Combo Boxes..?
Ok, a few things that might help clear things up.
As for what is returned, the repeat loop I set up just puts test response data into the array so you can see that the information matches the corresponding choices in the combo boxes. These also can contain whatever data you wish.
The user doesn't need to see numbers in the combo box. menuHistory returns the line number of the current selection. So if they've picked line 2, it returns a 2 etc. This is behind the scenes.
So the only thing to change would be the handler that fills the array. I just had the repeat loop do it with sample data because it was fast, and what is in it didn't really matter for the test.
In your case it does so instead of a repeat loop you can build the array by hand.
Ok, if we have this line.
and the user has picked line 1 of combo box 1, and line 2 of combo box 2 and line 1 of combo box 3, it will put "1,2,1" into the variable theIndex.
When building the array the keys of the array have to match the same format to make it easy to access the data in the array.
If you get your array properly setup, then the menuHistory line above will create a key that can access the correct entry in the array.
So if the user chose the first item of box 1, 3rd item of box 2 and 2nd item of box 3, theIndex would end up containing "1,3,2"
so theArray[theIndex] is the same as theArray["1,3,2"] and will retrieve whatever value you set up with that key in your array.
Does this make more sense, or am I off base as to what you were asking?
These can be whatever text/numbers you wish them to be. I put what I did into them just to let you know how things were setup. IE for the first combo box, the first line is box 1 1 because its in the first combo box adn is line 1. It really means nothing other than letting you compare the results with what is chosen. The lines of the combo box can say anything you wish and not affect the outcome.Also, the number choice on the all the combo's needs to be 1 2 3 not 31,32 etc
As for what is returned, the repeat loop I set up just puts test response data into the array so you can see that the information matches the corresponding choices in the combo boxes. These also can contain whatever data you wish.
The user doesn't need to see numbers in the combo box. menuHistory returns the line number of the current selection. So if they've picked line 2, it returns a 2 etc. This is behind the scenes.
So the only thing to change would be the handler that fills the array. I just had the repeat loop do it with sample data because it was fast, and what is in it didn't really matter for the test.
In your case it does so instead of a repeat loop you can build the array by hand.
Ok, if we have this line.
Code: Select all
put the menuHistory of button "combo1" & comma & the menuHistory of button "combo2" & comma & the menuHistory of button "combo3" into theIndex
When building the array the keys of the array have to match the same format to make it easy to access the data in the array.
Code: Select all
command setupArray
put "whatever you want to return if the user chooses item 1 box 1, item 1 box 2 and item 1 box 3" into theArray["1,1,1"]
-- the above line puts the data that is designated into an array theArray keyed by "1,1,1" .
-- you can get it out the same way. put theArray["1,1,1"] will locate the part of the array that matches the key "1,1,1" and put it wherever
-- you tell it to.
-- you need to setup a line for each possible combination that can occur with your combo boxes so..
put "whatever you want here, if the user chooses item 1 box 1, item 1 box 2, item 2 box 3" into the array["1,1,2"]
end setupArray
Code: Select all
put theArray[theIndex]
so theArray[theIndex] is the same as theArray["1,3,2"] and will retrieve whatever value you set up with that key in your array.
Does this make more sense, or am I off base as to what you were asking?
Re: MultiChoice Combo Boxes..?
ok, I have got it..!! ~ Can you check the code for me..?
Out of interest in the second 'setupArray', where did the i and the n and the x come from, I can't work out where they came from or see them referenced anywhere else..?
Also how can I stop either one of the combo's having a default value of 1..? When you start the app and choose one drop down choice it straight away brings up the answer (because it has got a 1 from the other combo, shouldn't have as it has not been picked yet.?), whilst this is not a problem as such its just a bit anoying..?
Last few questions is it possible to fix the size of the opened window to the actual size of the app (so that it appears more like a standalone app)..?
Very lastly, I have tried to insert the start time by saying:
on stack open
put time() into field "time"
end stack
but its not having it for some reason..?
Thanks
Code: Select all
local theArray
on menuPick pThePick
if theArray is empty then
setupArray
end if
put the menuHistory of button "combo1" & comma & the menuHistory of button "combo2" into theIndex
put theArray[theIndex] into field "outField"
end menuPick
command setupArray
put "3,1" into theArray["1,2"]
put "2,1" into theArray["1,3"]
put "3,2" into theArray["2,1"]
put "1,2" into theArray["2,3"]
put "2,3" into theArray["3,1"]
put "1,3" into theArray["3,2"]
end setupArray
command setupArray
repeat with i = 1 to 3
repeat with n = 1 to 3
put i & comma & n & comma & into theIndex
put "" & theIndex && "" into theArray[theIndex]
end repeat
end repeat
end setupArray
Also how can I stop either one of the combo's having a default value of 1..? When you start the app and choose one drop down choice it straight away brings up the answer (because it has got a 1 from the other combo, shouldn't have as it has not been picked yet.?), whilst this is not a problem as such its just a bit anoying..?
Last few questions is it possible to fix the size of the opened window to the actual size of the app (so that it appears more like a standalone app)..?
Very lastly, I have tried to insert the start time by saying:
on stack open
put time() into field "time"
end stack
but its not having it for some reason..?
Thanks
Re: MultiChoice Combo Boxes..?
remove the handler that contains the repeat loop. All it did was create sample data for my test stack. Replace it with the one you made, remove the other one completely.
The i, n and x are short term variables that are used in the repeat loop (that isn't needed anymore)
this code says to make a variable named i, put 1 in it, and repeat incrementing i until it reaches 3.
So the first look i = 1, 2nd loop i = 2, 3rd, i = 3, then the loop ends. The only reason that handler was there is to generate an array with 27 keys of sample data. You can look up repeat in the dictionary for more information.
The reason your stack open handler doesn't work is it's actually on stackOpen one word, then for the end its a matching end stackOpen
As for your hand built setupArray handler, I have a question or two.
You have 2 combo boxes with 3 menu choices in each. But your setupArray handler puts values into only six keys when there are actually 9 possible combinations.
Do you need a value for the option where the first item of combo box 1 is chose and first item of box 2 is chosen?
IE put "something" into theArray["1,1"] same for choosing items 1 and 3.. put "something else" into theArray["1,3"] and if the user choses item 3 and item 3, put "yet another something" into theArray["3,3"]
Of course if you only need the 6 listed values, ignore the above.
My apologies if i'm not explaining or understanding well. Its a foggy time of year for me.
The ["1,2"] in setupArray should directly correspond to the matching LINE number of what is chosen in each combo box.
The i, n and x are short term variables that are used in the repeat loop (that isn't needed anymore)
this code says to make a variable named i, put 1 in it, and repeat incrementing i until it reaches 3.
So the first look i = 1, 2nd loop i = 2, 3rd, i = 3, then the loop ends. The only reason that handler was there is to generate an array with 27 keys of sample data. You can look up repeat in the dictionary for more information.
Code: Select all
repeat with i = 1 to 3
end repeat
As for your hand built setupArray handler, I have a question or two.
You have 2 combo boxes with 3 menu choices in each. But your setupArray handler puts values into only six keys when there are actually 9 possible combinations.
Do you need a value for the option where the first item of combo box 1 is chose and first item of box 2 is chosen?
IE put "something" into theArray["1,1"] same for choosing items 1 and 3.. put "something else" into theArray["1,3"] and if the user choses item 3 and item 3, put "yet another something" into theArray["3,3"]
Of course if you only need the 6 listed values, ignore the above.
My apologies if i'm not explaining or understanding well. Its a foggy time of year for me.
The ["1,2"] in setupArray should directly correspond to the matching LINE number of what is chosen in each combo box.
Re: MultiChoice Combo Boxes..?
Hi sturgis ~ ok, have done that so the code becomes this (amazingly small.!):
Time: The time handler was actually correct I just mis-typed it in the reply to you, and it still refuses to work where ever I put it..?
6 Keys: The reason for that is that 1,1 and 2,2 and 3,3 are not conbinations that are required...
Mis-behaving Combo: What I was trying to say is when you first go into the app there are the two combo's with nothing showing or choosen, which is correct. Then you pick the first choice from combo1, but the answer comes up in fieldOut already becasue it is assuming or taking a default for combo2 as '1' (its definetly 1 not 2 or 3)... It shouldn't because it hasn't been picked yet so how does it know what I'm going to choose, see what I mean..? After that, it doesn't do it, as when you change one combo the answer doesn't change until you change the other combo, which is correct. It is only the first time it is used..?
"The ["1,2"] in setupArray should directly correspond to the matching LINE number of what is chosen in each combo box." - They do, thats not the problem...
As always thanks,
Code: Select all
local theArray
on menuPick pThePick
if theArray is empty then
setupArray
end if
put the menuHistory of button "combo1" & comma & the menuHistory of button "combo2" into theIndex
put theArray[theIndex] into field "outField"
end menuPick
command setupArray
put "3,1" into theArray["1,2"]
put "2,1" into theArray["1,3"]
put "3,2" into theArray["2,1"]
put "1,2" into theArray["2,3"]
put "2,3" into theArray["3,1"]
put "1,3" into theArray["3,2"]
end setupArray
Code: Select all
on stackopen
put time() into field "time"
end stackopen
Mis-behaving Combo: What I was trying to say is when you first go into the app there are the two combo's with nothing showing or choosen, which is correct. Then you pick the first choice from combo1, but the answer comes up in fieldOut already becasue it is assuming or taking a default for combo2 as '1' (its definetly 1 not 2 or 3)... It shouldn't because it hasn't been picked yet so how does it know what I'm going to choose, see what I mean..? After that, it doesn't do it, as when you change one combo the answer doesn't change until you change the other combo, which is correct. It is only the first time it is used..?
"The ["1,2"] in setupArray should directly correspond to the matching LINE number of what is chosen in each combo box." - They do, thats not the problem...
As always thanks,