Multiple Combo boxes, how ?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Multiple Combo boxes, how ?

Post by mydave » Mon Aug 08, 2005 9:51 pm

Hi,
Using the sample in the HELP file as follows:

Dialog>MyDialog
Caption=This is My Dialog
Left=300
Top=300
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,Line First%CRLF%Line Second%CRLF%Line Third
Button=Exit Macro,5,80,100,20,2
EndDialog>MyDialog

Show>MyDialog,result
MDL>%MyDialog.FirstBox%
MDL>%MyDialog.SecondBox%
Label>END

What I need is that, if user select an item in the SecondBox, then no data should be in the FirstBox.
I am trying to build a menu with multiple selections. The selections are grouped by area.
Your help would be much appreciated.

Thanks

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Tue Aug 09, 2005 12:55 am

Let me try to be a little clearer in the issue.

When I run the script, MDL shows a value in both, even though I only clicked and selected an item in the second combobox. For that reason, an 'IF' statement which was based on a value in the first combobox is always TRUE, even though nothing was selected from it (first combobox).

Did I do something wrong?

Again, I am trying to build a menu with several combo boxes. Each will have multiple selections. This would make it easier for users to use, rather than a long list which may be several hundreds to choose from.

Your help would be much appreciated.

Thanks.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 09, 2005 2:52 am

How about something like this:

Note there is nothing following the equal signs in the lines
Let>%MyDialog.FirstBox%= and Let>%MyDialog.SecondBox%=


Dialog>MyDialog
Caption=This is My Dialog
Left=300
Top=300
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,(NONE)%CRLF%,Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,(NONE)%CRLF%,Line First%CRLF%Line Second%CRLF%Line Third
Button=Exit Macro,5,80,100,20,2
EndDialog>MyDialog

Show>MyDialog,result
If>%MyDialog.FirstBox%=(NONE)
Let>%MyDialog.FirstBox%=
EndIf
If>%MyDialog.SecondBox%=(NONE)
Let>%MyDialog.SecondBox%=
EndIf
MDL>%MyDialog.FirstBox%
MDL>%MyDialog.SecondBox%
Label>END

Hope this helps,
Dick

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Tue Aug 09, 2005 10:06 am

Yes, it is close, but not quite.

I ran the script,

If the selection is in the secondbox, the value in the firstbox is garbage, which is good.

But if the selection is in the firstbox, the value of the firstbox is still garbage, which is not good

Thanks greatly for your quick help.
Sincerely

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Re: Multiple Combo boxes, how ?

Post by support » Tue Aug 09, 2005 10:16 am

mydave wrote:Hi,
Using the sample in the HELP file as follows:

Dialog>MyDialog
Caption=This is My Dialog
Left=300
Top=300
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,Line First%CRLF%Line Second%CRLF%Line Third
Button=Exit Macro,5,80,100,20,2
EndDialog>MyDialog

Show>MyDialog,result
MDL>%MyDialog.FirstBox%
MDL>%MyDialog.SecondBox%
Label>END

What I need is that, if user select an item in the SecondBox, then no data should be in the FirstBox.
I am trying to build a menu with multiple selections. The selections are grouped by area.
Your help would be much appreciated.

Thanks
To do this you will need to show the dialog NON modal and have an action loop in which you can detect the value of the dialog and change the contents of another accordingly.

Trying to do it with a modal dialog as in this example makes no sense since the dialog has to be closed before any values can be returned.
MJT Net Support
[email protected]

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 09, 2005 1:44 pm

mydave,

You must have been right on the spot when I posted this.

Initially there was a mistake in one of the "if" statements. I caught it and edited the posting within a couple of minutes. I think if you recopy the code posted by me at 8:52 on Aug 08, 2005, it will work as advertised.

Hopefully I'm understanding what you are looking for. Support's response would be true if you wanted to make it impossible for a user to pick from more than one combo box, but that's not what I read in your post. However, if that is the case then what I wrote will not be adequate, you will need to do what support has suggested.

Hope this is helpful,
Dick

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Tue Aug 09, 2005 8:36 pm

Hi Support & JRL,

I tried the NON model solution as attached, but the script does not let the selection in the secondbox. Users should be able to select one, and ONLY one, either in the firstbox or in the secondbox, but not both.

Your help to correct the attached script would be most appreciated:


Dialog>MyDialog
Caption=This is My NON MODAL Dialog
Left=300
Top=300
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,Line First%CRLF%Line Second%CRLF%Line Third
Button=Write Result,5,80,100,20,3
EndDialog>MyDialog

Label>Start

Show>MyDialog

Label>ActionLoop
GetDialogAction>MyDialog,r
GetDate>time
If>r=2,END
If>r=3,Checkselection
Wait>.5

Goto>ActionLoop

Label>Checkselection
If>%MyDialog.FirstBox%=Line One,LINEONE
If>%MyDialog.FirstBox%=Line Two,LINETWO
If>%MyDialog.FirstBox%=Line Three,LINETHREE
If>%MyDialog.SecondBox%=Line First,LINETFIRST
If>%MyDialog.SecondBox%=Line Second,LINESECOND
If>%MyDialog.SecondBox%=Line Third,LINETHIRD
ResetDialogAction>MyDialog

Label>LINEONE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINEONE was selected.
Goto>Start
Label>LINETWO
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETWO was selected.
Goto>Start
Label>LINETHREE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETHREE was selected.
Goto>Start
Label>LINETFIRST
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line First was selected.
Goto>Start
Label>LINESECOND
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Second was selected.
Goto>Start
Label>LINETHIRD
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Third was selected.
Goto>Start
Label>END

[/b]

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 09, 2005 10:38 pm

Try this, Let me know....


Dialog>MyDialog
Caption=This is My NON MODAL Dialog
Top=100
Width=305
Left=100
Height=150
Label=Test Multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,NONE%CRLF%Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,NONE%CRLF%Line First%CRLF%Line Second%CRLF%Line Third
Button=Write Result,5,80,100,33,3
EndDialog>MyDialog

Let>LastChoice=
Let>k=0
Label>Start
Show>MyDialog

Label>ActionLoop
GetDialogAction>MyDialog,r
GetDate>time
Let>k=k+1
If>r=2,END
If>r=3,Checkselection
If>OneChoiceMade=1
GoSub>ManageBoxes
Goto>ActionLoop
EndIf
If>%MyDialog.FirstBox%NONE
Let>OneChoiceMade=1
Let>LastChoice=FirstBox
EndIf

If>%MyDialog.SecondBox%NONE
Let>OneChoiceMade=1
Let>LastChoice=SecondBox
EndIf
Goto>ActionLoop

SRT>ManageBoxes
If>{(%MyDialog.FirstBox%"NONE") AND (%LastChoice%="SecondBox")}
Let>LastChoice=FirstBox
Let>MyDialog.SecondBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf
If>{(%MyDialog.SecondBox%"NONE") AND (%LastChoice%="FirstBox")}
Let>LastChoice=SecondBox
Let>MyDialog.FirstBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf

END>ManageBoxes

Label>Checkselection
CloseDialog>MyDialog
MDL>The Action loop has cycled %k% times.
If>%MyDialog.FirstBox%=Line One,LINEONE
If>%MyDialog.FirstBox%=Line Two,LINETWO
If>%MyDialog.FirstBox%=Line Three,LINETHREE
If>%MyDialog.SecondBox%=Line First,LINETFIRST
If>%MyDialog.SecondBox%=Line Second,LINESECOND
If>%MyDialog.SecondBox%=Line Third,LINETHIRD
Goto>Start

Label>LINEONE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINEONE was selected.
MDL>%time% - FirstBox LINEONE was selected.
Goto>Start
Label>LINETWO
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETWO was selected.
MDL>%time% - FirstBox LINETWO was selected.
Goto>Start
Label>LINETHREE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETHREE was selected.
MDL>%time% - FirstBox LINETHREE was selected.
Goto>Start
Label>LINETFIRST
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line First was selected.
MDL>%time% - SecondBox Line First was selected.
Goto>Start
Label>LINESECOND
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Second was selected.
MDL>%time% - SecondBox Line Second was selected.
Goto>Start
Label>LINETHIRD
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Third was selected.
MDL>%time% - SecondBox Line Third was selected.
Goto>Start
Label>END


Hope this works....
Dick
Last edited by JRL on Wed Aug 10, 2005 3:38 am, edited 2 times in total.

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Wed Aug 10, 2005 12:53 am

Hi JRL,

I really am lost in the logic that you were using. Anyway, I did try it, again and again. The script still works if a selection was made in the FIRSTbox. If a selection was in the SECONDbox, the selection is default back to the last selection in the FIRSTbox.

And the script is slow, meaning that I got to click on the button 'Write Result' a few times before the test.txt is written.

I did not think that this was easy, but did not expect it to be this hard, LOL.
Please don't give up on me.

Thanks.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 10, 2005 2:57 am

mydave,

I edited the posting above rather than post the whole thing again. It didn't work correctly anyway because the line "Let>LastChoice=" came after the Start label. This caused a problem on the repeat of the dialog. Also added a Close dialog line trying to make the selection of the "Write Result" button more reliable. Also made the Button bigger for the same reason. Seemed to help a little but sometimes it still needs to be picked several times before it is activated.

Added a couple of message boxes just to see how things are working.

See if this is any more acceptable.

Perhaps Support or someone more knowledgeable than I am can explain why the "Write Result" button is so unreliable.

I won't give up. But I'm pushing the limits of my knowledge. Of course that's what makes it fun.

Give this a try and let me know,
Dick

Edit-1

Changed the above script again, moved the "ResetDialogAction>MyDialog" from the end of the ManageBoxes subroutine and put it directly in the the two if statements. I don't know why but this change seems to allow the "Write Result" button to be reliable. Hope it works for you as well as it works for me.

Good luck,
Dick

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Wed Aug 10, 2005 9:56 am

Hey Dick,

he he he he he ! ! !

IT WORKS

My next step is trying to understand the logic that you coded and then put it to use. Simple need but WOW lot of coding to make it happens.

Thanks and thanks and thanks.

Dave

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Wed Aug 17, 2005 6:06 pm

Would Support jump in and lend a hand please.
Two boxes work fine, but more for than two, it is another challenge.
Thanks

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 17, 2005 8:53 pm

mydave,

If support has a better way to accomplish this that would be great. In case they do not, here is the same thing with a third box. I added some notes to hopefully make it easier for you to understand how to add capability for more combo boxes. Sorry if the logic is hard to follow, I don't know how to do this any easier.

How many boxes do you need? Post the dialog box you want and if its not too outrageous, I'll try to make it work for you.
try this:



Dialog>MyDialog
Caption=This is My NON MODAL Dialog
Left=300
Top=300
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=FirstBox,50,30,200,NONE%CRLF%Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=SecondBox,50,50,200,NONE%CRLF%Line First%CRLF%Line Second%CRLF%Line Third
ComboBox=ThirdBox,50,70,200,NONE%CRLF%Line 1%CRLF%Line 2%CRLF%Line 3
Button=Write Result,5,100,100,20,3
EndDialog>MyDialog

Let>LastChoice=
Label>Start
Show>MyDialog

Label>ActionLoop
GetDialogAction>MyDialog,r
GetDate>time
If>r=2,END
If>r=3,Checkselection
//Wait>.5
If>OneChoiceMade=1
GoSub>ManageBoxes
Goto>ActionLoop
EndIf
If>%MyDialog.FirstBox%NONE
Let>OneChoiceMade=1
Let>LastChoice=FirstBox
EndIf
EndIf
If>%MyDialog.SecondBox%NONE
Let>OneChoiceMade=1
Let>LastChoice=SecondBox
EndIf
////////Add another one of these for more boxes////////
If>%MyDialog.ThirdBox%NONE
Let>OneChoiceMade=1
Let>LastChoice=ThirdBox
EndIf
///////////////////////////////////////////////////////
Goto>ActionLoop

SRT>ManageBoxes
////////Add another one of these for more boxes////////
If>{(%MyDialog.FirstBox%"NONE") AND (%LastChoice%="SecondBox")}
Let>LastChoice=FirstBox
Let>MyDialog.SecondBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf
////////And you have to add another "IF" statement////////
///To each of these groups within the subroutine to check
///for the condition that a new box has been selected and
///the last selected box should be turned off////////////
If>{(%MyDialog.FirstBox%"NONE") AND (%LastChoice%="ThirdBox")}
Let>LastChoice=FirstBox
Let>MyDialog.ThirdBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf
///////////////////////////////////////////////////////

If>{(%MyDialog.SecondBox%"NONE") AND (%LastChoice%="FirstBox")}
Let>LastChoice=SecondBox
Let>MyDialog.FirstBox.ItemIndex=0
Let>MyDialog.ThirdBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf
If>{(%MyDialog.SecondBox%"NONE") AND (%LastChoice%="ThirdBox")}
Let>LastChoice=SecondBox
Let>MyDialog.ThirdBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf


If>{(%MyDialog.ThirdBox%"NONE") AND (%LastChoice%="FirstBox")}
Let>LastChoice=ThirdBox
Let>MyDialog.FirstBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf
If>{(%MyDialog.ThirdBox%"NONE") AND (%LastChoice%="SecondBox")}
Let>LastChoice=ThirdBox
Let>MyDialog.SecondBox.ItemIndex=0
ResetDialogAction>MyDialog
EndIf

END>ManageBoxes

Label>Checkselection
If>%MyDialog.FirstBox%=Line One,LINEONE
If>%MyDialog.FirstBox%=Line Two,LINETWO
If>%MyDialog.FirstBox%=Line Three,LINETHREE

If>%MyDialog.SecondBox%=Line First,LINETFIRST
If>%MyDialog.SecondBox%=Line Second,LINESECOND
If>%MyDialog.SecondBox%=Line Third,LINETHIRD

////////Add another one of these for more boxes////////
If>%MyDialog.ThirdBox%=Line 1,LINE1
If>%MyDialog.ThirdBox%=Line 2,LINE2
If>%MyDialog.ThirdBox%=Line 3,LINE3
///////////////////////////////////////////////////////


Label>LINEONE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINEONE was selected.
Goto>Start
Label>LINETWO
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETWO was selected.
Goto>Start
Label>LINETHREE
WriteLn>c:\temp\test.txt,result,%time% - FirstBox LINETHREE was selected.
Goto>Start

Label>LINETFIRST
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line First was selected.
Goto>Start
Label>LINESECOND
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Second was selected.
Goto>Start
Label>LINETHIRD
WriteLn>c:\temp\test.txt,result,%time% - SecondBox Line Third was selected.
Goto>Start

////////Add another one of these for more boxes////////
Label>LINE1
WriteLn>c:\temp\test.txt,result,%time% - ThirdBox Line 1 was selected.
Goto>Start
Label>LINE2
WriteLn>c:\temp\test.txt,result,%time% - ThirdBox Line 2 was selected.
Goto>Start
Label>LINE3
WriteLn>c:\temp\test.txt,result,%time% - ThirdBox Line 3 was selected.
Goto>Start
///////////////////////////////////////////////////////

Label>END




Hope this is helpful,
Dick

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Thu Aug 18, 2005 12:30 am

Hi Dick,
I spent the whole day trying to understand your script. I turned on log file and inserted MDL at certain points in order to see how the variables changed. But not until you responded with the last change that I got a 'somewhat' grip on your logic.

The part in your logic that is crucial and most difficult to understand is ManageBoxes. Within this subroutine, for two comboboxes, two IF statements are needed. For three, it requires six. For four, it will require twelve. My dialogue would require 16 to 20 comboboxes. So a quick estimate, I would need to use 380 IF statements.

I wonder how the script would run then. The computers that would run the script are P4 1.6 and 256mb. Perhaps it would be fine.

Nevertheless, this subroutine is genius, and you are so darn quick to figure it out. I understand the rest of the script, so I will use this logic to get the menu done.

You have done so much. And for that I am most gratefull.
I will respond back when the script is complete, and most importantly, how it performs.

Sincerely,

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 18, 2005 5:27 am

mydave,

Not well tested but I think this revised script will simplify your task.

The logic is close to the same as before, it just uses arrayed variables to make it flexible. Define your Combo Boxes making sure you follow the naming convention, and set the "BoxQty" variable to the total number of Combo Boxes and that should be all thats needed. I'm not sure how speed will be affected as the number of Boxes goes up. You'll just have to try it.

Try this let me know how it works:



CreateDir>C:\Temp
Dialog>MyDialog
Caption=This is My NON MODAL Dialog
Left=300
Top=100
Width=305
Height=150
Label=Test multiple ComboBoxes:,5,5
ComboBox=Box1,50,30,200,NONE%CRLF%Line One%CRLF%Line Two%CRLF%Line Three
ComboBox=Box2,50,50,200,NONE%CRLF%Line First%CRLF%Line Second%CRLF%Line Third
ComboBox=Box3,50,70,200,NONE%CRLF%Line 1%CRLF%Line 2%CRLF%Line 3
Button=Write Result,5,100,100,20,3
EndDialog>MyDialog
///Be sure ComboBoxes are named Box1, Box2, Box3, Etc...


///Enter the number of boxes defined as BoxQty=xxx
Let>BoxQty=3
Let>LastChoice=
Label>Start
Show>MyDialog

Label>ActionLoop
GetDialogAction>MyDialog,r
GetDate>time
If>r=2,END
If>r=3,Checkselection
If>OneChoiceMade=1
GoSub>ManageBoxes
Goto>ActionLoop
EndIf
Let>k=0
Repeat>k
Let>k=k+1
Let>BoxSel=MyDialog.Box%k%
If>%BoxSel%NONE
Let>OneChoiceMade=1
Let>LastChoice=Box%k%
EndIf
Until>k,%BoxQty%
Goto>ActionLoop

SRT>ManageBoxes
Let>kk=0
Repeat>kk
Let>kk=kk+1
GoSub>ResetBoxes
Until>kk,%BoxQty%
END>ManageBoxes

SRT>ResetBoxes
Let>ChoiSel=Box%kk%
Let>DiaBoxSel=MyDialog.Box%kk%.ItemIndex
If>%DiaBoxSel%=0,ResetEnd
If>%LastChoice%=%ChoiSel%,ResetEnd
Let>MyDialog.%LastChoice%.ItemIndex=0
Let>LastChoice=%ChoiSel%
EndIf
ResetDialogAction>MyDialog
EndIf
Label>ResetEnd
END>ResetBoxes

Label>Checkselection
//Separate>MyDialog.%LastChoice%.Items.Text,%CRLF%,selvar
//MidStr>LastChoice,4,1,Box
//Let>Box=Box+1
//Let>Selection=selvar_%Box%
Let>Selection=MyDialog.%LastChoice%
WriteLn>c:\temp\test.txt,result,%time% - %LastChoice% %Selection% was selected.
Message>%time% - %LastChoice% %Selection% was selected.
Goto>Start

Label>END


Hope this is useful,
Dick
Last edited by JRL on Fri Aug 19, 2005 3:46 am, edited 2 times in total.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts