Combobox newbie Q
Moderators: Dorian (MJT support), JRL
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Combobox newbie Q
I don't normally use dialogs but now I have a question. Can a combo box return a value other than what is displayed? To take a simple example, if the combobox choices are Red, Yellow, Green, Blue, and I want to get 1, 2, 3, 4 or non sequential numbers or alphas like SDF35435, HK98675, TYH21366, BFDB64325 returned, is there a direct way to do that in the dialog code?
Not sure I understand what you're asking but I'll take a stab at it anyway.
If you step through your script in the editor you'll see that the combobox will generate a variable named dialogname.comboboxname.itemindex based on the selection made by the dialog user. itemindex starts at 0 rather than 1 so you might want to add 1 to the result but this could then be used to pull the nth item from another list.
helpful?
If you step through your script in the editor you'll see that the combobox will generate a variable named dialogname.comboboxname.itemindex based on the selection made by the dialog user. itemindex starts at 0 rather than 1 so you might want to add 1 to the result but this could then be used to pull the nth item from another list.
helpful?
Why not something like this?
Code: Select all
Dialog>Dialog1
Caption=Dialog1
Width=294
Height=97
Top=CENTER
Left=CENTER
ComboBox=msComboBox1,8,24,145,-Select-%CRLF%Red%CRLF%Yellow%CRLF%Green%CRLF%Blue
Label=Part Number,8,8,true
Button=GO,160,24,75,25,100
EndDialog>Dialog1
show>Dialog1
Label>ActionLoop
wait>0.01
GetDialogAction>Dialog1,r
IF>r=100,PartNumber
IF>r=2,Exit
goto>ActionLoop
Label>PartNumber
IF>Dialog1.msComboBox1=Red
let>Dialog1.msLabel1=Part Number: A123A
ENDIF
IF>Dialog1.msComboBox1=Yellow
let>Dialog1.msLabel1=Part Number: B123B
ENDIF
IF>Dialog1.msComboBox1=Green
let>Dialog1.msLabel1=Part Number: C123C
ENDIF
IF>Dialog1.msComboBox1=Blue
let>Dialog1.msLabel1=Part Number: D123D
ENDIF
ResetDialogAction>Dialog1
goto>ActionLoop
Label>Exit
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Thanks Rain, that's very helpful, it jump started my coding. Thanks Dick too for the itemindex clue. In the code below the part name/number data is all in the partcat variable (could be in a file too). This makes it easy to maintain, and new parts can be added just by adding the name/number pair to partcat. There are no stacked If's to be edited or added.
Let>comma=,
Let>partcat=Red,A123A Yellow,B123B Green,C123C Blue,D123D Puce,E345E
Separate>partcat, ,part_list
If>part_list_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Separate>part_list_%k%,comma,parts
Let>partnam[%k%]=parts_1
Let>partnum[%k%]=parts_2
Until>k,part_list_count
Let>dialist=
Let>k=0
Repeat>k
Let>k=k+1
Concat>dialist,%CRLF%
Concat>dialist,partnam[%k%]
Until>k,part_list_count
Dialog>Dialog1
Caption=Dialog1
Width=294
Height=97
Top=CENTER
Left=CENTER
ComboBox=msComboBox1,8,24,145,-Select-%dialist%
Label=Part Number,8,8,true
Button=GO,160,24,75,25,100
EndDialog>Dialog1
show>Dialog1
Label>ActionLoop
wait>0.01
GetDialogAction>Dialog1,r
IF>r=100,PartNumber
IF>r=2,Exit
goto>ActionLoop
Label>PartNumber
ResetDialogAction>Dialog1
Let>listnum=Dialog1.msComboBox1.itemindex
Let>part_num=partnum[%listnum%]
Let>dialabel=Part Number:
ConCat>dialabel,part_num
let>Dialog1.msLabel1=dialabel
goto>ActionLoop
Label>Exit
Let>comma=,
Let>partcat=Red,A123A Yellow,B123B Green,C123C Blue,D123D Puce,E345E
Separate>partcat, ,part_list
If>part_list_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Separate>part_list_%k%,comma,parts
Let>partnam[%k%]=parts_1
Let>partnum[%k%]=parts_2
Until>k,part_list_count
Let>dialist=
Let>k=0
Repeat>k
Let>k=k+1
Concat>dialist,%CRLF%
Concat>dialist,partnam[%k%]
Until>k,part_list_count
Dialog>Dialog1
Caption=Dialog1
Width=294
Height=97
Top=CENTER
Left=CENTER
ComboBox=msComboBox1,8,24,145,-Select-%dialist%
Label=Part Number,8,8,true
Button=GO,160,24,75,25,100
EndDialog>Dialog1
show>Dialog1
Label>ActionLoop
wait>0.01
GetDialogAction>Dialog1,r
IF>r=100,PartNumber
IF>r=2,Exit
goto>ActionLoop
Label>PartNumber
ResetDialogAction>Dialog1
Let>listnum=Dialog1.msComboBox1.itemindex
Let>part_num=partnum[%listnum%]
Let>dialabel=Part Number:
ConCat>dialabel,part_num
let>Dialog1.msLabel1=dialabel
goto>ActionLoop
Label>Exit