Script Dialog > Simple Dialog > Dlg.Control("Combo_Box") > DialogListItem access

Greetings Opus Comrades
Below is a troubleshooting/sample script of a Script Dialog of the Simple variety.

Scenario
I believe the object hierarchy at play is that in the topic name.
That is
Script Dialog > Simple Dialog > Dlg.Control("Combo_Box") > DialogListItem.

Objective
I want to access more stuff from my Combo Box.
The only thing I get currently is an integer representing the pulldown list number I have selected when running the script.
That is obtained from these lines in the script:

  DOpus.Output "   010   Combo_Box index       = " & Dlg.Control("Combo_Box").value
  Combo_Box_Index = Dlg.Control("Combo_Box").value

For example you will note that I reproduce the Combo_Box items in an array in the script:

Pulldown_Array = Array(Entry01,Entry02,Entry03,Entry04,Entry05)

Q1 - Can I not pull this in from the dialog somehow?
Maybe via access to the DialogListItem that I read the Combo_Box returns?
Q2 - In the context of this sample script, what else can DialogListItem give me?

How to Access DialogListItem
Is Combo_Box_Index a DialogListItem object?
When I tried to reference say Combo_Box_Index.index like this:
DOpus.Output " 035 Combo_Box_Test_Entry.index = " & Combo_Box_Test_Entry.index

I got an error basically telling me that was not an object:


So then
Q3 - How do I access DialogListItem?

Working Script Run Through
There script and supporting dialog xml is at the bottom of this post.



image

Script Details

Function OnClick(ByRef clickData)

      DOpus.ClearOutput
      DOpus.Output "001000 Start"
'  001000
'  001000 Start
'  001000
    Pulldown_Array = Array("Entry01","Entry02","Entry03","Entry04","Entry05")
    Set Dlg = DOpus.Dlg
    Dlg.window = clickData.func.sourcetab
    Dlg.template = "dialog1"
    retVal = Dlg.Show()
'  002000
'  002000 Results
'  002000
      DOpus.Output "002000 Results"
      DOpus.Output "   010   Combo_Box index       = " & Dlg.Control("Combo_Box").value
      Combo_Box_Index = Dlg.Control("Combo_Box").value
      DOpus.Output "   020   Combo_Box_Index       = " & Combo_Box_Index
      Combo_Box_Test_Entry = Pulldown_Array(Combo_Box_Index)
      DOpus.Output "   030   Combo_Box_Test_Entry  = " & Combo_Box_Test_Entry

 '     DOpus.Output "   035   Combo_Box_Test_Entry.index  = " & Combo_Box_Test_Entry.index    < Error if included


      DOpus.Output "   040   Suffix                = " & Dlg.Control("Suffix").value
      Suffix_Entry = Dlg.Control("Suffix").value
      DOpus.Output "   050   Dlg.result            = " & Dlg.result
      DOpus.Output "   060   Return code           = "  & retVal
      if ratVal = "0" then
          DOpus.Output "   070   Dlg.result = 0 so want top exit"
        end if
'  003000
'  003000 Case Statement
'  003000
      DOpus.Output "003000 Case statement"
      '
      Select Case Combo_Box_Test_Entry
        Case "Entry01"
          DOpus.Output("   020b    Combo_Box         = " & Dlg.Control("Combo_Box").value)
        Case "Entry02"
		
        Case Else
      End Select
      DOpus.Output("004000 End")
End Function

**Accompanying Dailog XML**
<resources>
	<resource name="dialog1" type="dialog">
		<dialog fontsize="8" height="60" lang="english" standard_buttons="ok,cancel" title="Prepare to Go" width="180">
			<control height="40" name="Combo_Box" type="combo" width="64" x="24" y="24">
				<contents>
					<item text="Entry01" />
					<item text="Entry02" />
					<item text="Entry03" />
					<item text="Entry04" />
					<item text="Entry05" />
				</contents>
			</control>
			<control halign="left" height="12" name="Suffix" tip="Suffix" type="edit" width="64" x="96" y="24" />
		</dialog>
	</resource>
</resources>

Script Dialog Screenshot


Start Again! Debuggginh.dcf (4.9 KB)

The error is partly because the code was trying to use its own string as if it was an object. Basically, this:

    Pulldown_Array = Array("Entry01","Entry02","Entry03","Entry04","Entry05")
    Combo_Box_Test_Entry = Pulldown_Array(2)
    DOpus.Output "index = " & Combo_Box_Test_Entry.index ' Error

Combo_Box_Test_Entry will be one of the strings from Pulldown_Array, which won't have an index property. No Opus objects involved there.

The code should be using the thing that Dlg.Control("...").value returns. If VBScript wasn't terrible, you'd just need to do this:

    Combo_Box_Index = Dlg.Control("Combo_Box").value
    DOpus.Output "index = " & Combo_Box_Index.index ' Still an error...

That still errors because Combo_Box_Index is (surprisingly) just a numeric index, not the object you're expecting. (I guess because VBScript assigns the temporary object's default value to the variable, which is the index in this case.)

Since VBScript is a terrible language, you need to remember to use Set when assigning an object to a variable, or it won't work as expected. This then works:

    Set Combo_Box_Index = Dlg.Control("Combo_Box").value
    DOpus.Output "index = " & Combo_Box_Index .index ' Works

This Set nonsense is one reason to use JScript instead of VBScript, as you don't have to worry about it there. :slight_smile: (On the flip side, looping through lists/collections is more of a pain in JScript than VBScript, but I think that trade-off is worth it.)

A short complete example, using the same dialog resources as before:

(Edit: The Pulldown_Array line can be removed as nothing uses it. It's leftover from the original code. The values are defined in the resource, which is in one of the posts above.)

Function OnClick(ByRef clickData)

    Pulldown_Array = Array("Entry01","Entry02","Entry03","Entry04","Entry05")
    Set Dlg = clickData.func.dlg
    Dlg.template = "dialog1"
    retVal = Dlg.Show()

    Set Combo_Box_Value = Dlg.Control("Combo_Box").value
    DOpus.Output "Combo_Box_Value = " & Combo_Box_Value
    DOpus.Output "Combo_Box_Value.index = " & Combo_Box_Value.index
	DOpus.Output "Combo_Box_Value.label = " & Combo_Box_Value.name

End Function

1 Like

Wonderful! Thanks Leo
I will take a little time to absorb...
Very very helpful thank you