How do I list the controls in a dialog?

I am debugging some freeware code as an addin to Calc and I am having 2 problems. Here is the subroutine I am having a problem with. When I invoke it I get an error when I try to reset the value of OptionIDontCare. I get the following error:
BASIC runtime error. Object variable not set.

Sub OptionIDontCare_Click()
Field = "<" & sOptionIDontCare & ">"
If oDialog1.GetControl("OptionIDontCare").State = True Then
    oDialog1.GetControl("TextFieldOrder").Text = _  
      oDialog1.GetControl("TextFieldOrder").Text + Field & " "
    QIFFields(iCol) = Field
    iCol = iCol + 1
    OptionIDontCare.Value = False
End If
End Sub

I have 2 problems. The first is how do I change the value of OptionIDontCare.State? Are State and Value the same thing?
The second is I cannot find the OptionIDontCare control. How can I list the names of the controls in a dialog?

Thank you,
Vince Radice

(Formatting rectified by @Lupp )

Thank you @Lupp for reformatting the code.

Hello @vhradice,

Starting with dialog control names. An actual list won’t be much help if you don’t know the type of control it is associated with. The easier method is to go to the Basic IDE and select the Dialog control you are dealing with. Then select a control and its information will display in lower left corner view. Example:

Here the option button control was selected & its name is OptionButton1. This will give you the needed names.

Changing values of a control dependent entirely on what type of control you are dealing with. Option Button and Check Box deal with a state meaning On or Off (checkbox has a third state Not Defined). Other controls use either Value or Text to change the data. This depends upon the control and type of data.

So in dealing with a ‘Option Button’ or ‘Check Box’, the State would be 1 or True to represent ON and 0 or False to represent OFF.

Hello @vhradice,

To change the State of your optionbutton “OptionIDontCare”, you could call:

oDialog.getControl( "OptionIDontCare" ).State = False

To get the list of controls on your dialog, just call its method oDialog.getControls()
For example:

Dim i As Integer
For i = 0 To uBound( oDialog.getControls() )
	msgbox oDialog.getControls()( i ).Model.Name
Next i

The variable oDialog should be declared as Object elsewhere in the module, e.g.:

Private oDialog As Object