Combobox newbie Q

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Combobox newbie Q

Post by Me_again » Fri Jun 01, 2007 6:47 pm

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?

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

Post by JRL » Fri Jun 01, 2007 7:46 pm

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?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jun 01, 2007 8:04 pm

I see, so I have to put the values I want in an array, and use the itemindex to retrieve them ?

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

Post by JRL » Fri Jun 01, 2007 8:46 pm

Could do that. Where are the values now?

You could retrieve them from a file using ReadLn> or use Separate> to get them from a list.

In any case there is nothing that I know of built into dialogs to associate an "outside" list of items to the list shown in a combo box.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jun 01, 2007 9:01 pm

It would only be maybe 12 items max so it's easy to just put them in the script.

Seems like it might be a nice feature, I would imagine there are a lot of situations where you would want to present the user with an easily recognized label, but have the dialog return a code or part number.

Thanks :D

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Jun 02, 2007 11:17 am

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Jun 02, 2007 6:00 pm

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

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jun 04, 2007 5:05 pm

Glad I could help :)

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