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

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