DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

refer to comboboxes in a dialog box by variable

Solved!
Go to solution

Hi, I'm writing some script to fill the list choices in 17 comboboxes on my form.  Currently I have something that looks like below.  You can see there is a commented out try at a for loop to replace the 17 discrete combobox lines below it.  I can't seem to figure out how to refer to the 17 comboboxes by setting some variable and then doing it in a for loop.  Ideas?

 

I am getting an error that says I can't use parentheses when calling a sub when it tries to evaluate the mybox.items.add command.

 

 

'get each name in each group, populate list boxes
for j = 0 to (numgrps)
for z = 1 to oDlgParams(j).run_num_tags
'for k = 1 to 17
' set mybox = combobox & k
' mybox.items.add(oDlgParams(j).listbox_entry(z),z)
'next
Call ComboBox1.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox2.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox3.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox4.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox5.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox6.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox7.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox8.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox9.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox10.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox11.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox12.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox13.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox14.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox15.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox16.Items.Add(oDlgParams(j).listbox_entry(z),z)
Call ComboBox17.Items.Add(oDlgParams(j).listbox_entry(z),z)
next
next

 

 

0 Kudos
Message 1 of 6
(2,802 Views)
Solution
Accepted by topic author jheadley

You can use an array to do an indirection.

dim boxes : boxes = Array(ComboBox1, ComboBox2, ComboBox3, ComboBox4)

dim mybox  : for each mybox in boxes
  call mybox.items.add(oDlgParams(j).listbox_entry(z),z)
next

And you have to add `call` to call methods with more than one parameter.

0 Kudos
Message 2 of 6
(2,758 Views)

OK thanks, the code below works.  But is there a way to use a loop command to fill the boxes array instead of writing out 17 instances of combobox#?

 

 

boxes = Array(Combobox1,combobox2,combobox3,combobox4,combobox5,combobox6,combobox7,combobox8,combobox9,combobox10,combobox11,combobox12,combobox13,combobox14,combobox15,combobox16,combobox17)

'get each name in each group, populate list boxes
for j = 0 to (numgrps)
  for z = 1 to oDlgParams(j).run_num_tags
    for each mybox in boxes
      call mybox.items.add(oDlgParams(j).listbox_entry(z),z)
    next
  next
next

0 Kudos
Message 3 of 6
(2,749 Views)

I assume that whatever method could be used to fill the array might also be useful to assign the values of the comboboxes.  Currently I'm struggling to come up with a better way to fill them than this:


combobox1.Value = 1
combobox2.Value = 2
combobox3.Value = 3
combobox4.Value = 4
combobox5.Value = 5
combobox6.Value = 6
combobox7.Value = 7
combobox8.Value = 8
combobox9.Value = 9
combobox10.Value = 10
combobox11.Value = 11
combobox12.Value = 12
combobox13.Value = 13
combobox14.Value = 14
combobox15.Value = 15
combobox16.Value = 16
combobox17.Value = 17

0 Kudos
Message 4 of 6
(2,748 Views)

Never mind the value assignment question, I came up with this:

j = 1
for each mybox in boxes
  mybox.value = j
  j = j + 1
next

 

0 Kudos
Message 5 of 6
(2,746 Views)
Sub Dialog_EventInitialize(ByRef This) 'Created Event Handler

  dim ctrl : for each ctrl in this.Controls
    MsgBox ctrl.ObjectType & " / " & ctrl.ObjectCode
  Next

End Sub

There is also the ability to loop all controls of an dialog.

0 Kudos
Message 6 of 6
(2,738 Views)