Radio Button Controls

Description

This page describes how to create radio button controls and how to test a radio control's variable.

To create a radio button control on a dialog you also use the '(' and ')' delimiters, but you include an enclosed "=" sign after the variable name, followed by a specifier that indicates what choices the radio button displays. You can specify the choices for the radio button in one of three ways:

  • enclosing a comma separated list between '{' and '}' e.g. {Red,Green,Blue}

  • By referring to an array that contains the choices

  • By referring to a string variable that contains a CR-LF delimited list of choices.

The syntax for a check box object is:

(variable_name={choice1,choice2,choiceN})
(variable_name=choice_variable)
(variable_name=choice_array)

Where choice1, choice2, choiceN are the actual choices, or choice_variable is the name of a string that contains CR-LF delimited choices, or choice_array is the name of a array that contains the choices. If variable_name is undeclared, or is declared as a character value, the value of variable_name will be a string equal to the text of the selected radio button. If variable_name is declared as a numeric value, it will be equal to the ordinal value of the button (i.e. 1 if button 1 is selected, 2 if button 2 is selected, and so on). The following script displays a dialog with three radio buttons:

mode = 1
result=ui_dlg_box("Title",<<%dlg%
Filename: [.32filename];
Open as? ;
(mode={Shared,Read only,Exclusive});

%dlg% )

Radio Button Control

images/XD_Radio_button_control_1.gif

In this example, since mode is set to 1 (which implicitly dimensions mode as a numeric variable) before the dialog is displayed, the dialog box will set the value of mode to 1, 2 or 3, depending on which button was selected when the dialog was closed. In addition, when the dialog is first displayed, the first choice will be selected. If, for example, you wanted the dialog to be displayed with the "Exclusive" choice selected, you would issue the following command before displaying the dialog:

mode = 3

Testing a Radio Control's Variable

If you had not initialized mode before displaying the dialog, or if you had explicitly declared mode as a character variable, or if you had implicitly declared it as a character variable (for example, by issuing the command mode = "Exclusive" to set "Exclusive" as the default selected radio button), then mode would be set to "Shared", "Read only" or "Exclusive". The following script demonstrates this:

Dim mode as C
result=ui_dlg_box("Title",<<%dlg%
Filename: [.32filename];
Open as? ;
(mode={Shared,Read only,Exclusive});

%dlg% )
if result = "OK" then
   ui_msg_box("Result","User selected option: "+mode)
end if

Limitations

Desktop applications only

See Also