Purpose
Changes the status of a control in the active custom dialog box.
Syntax
Alter Control id_num
[ Title { title | From Variable array_name } ]
[ Value value ]
[ { Enable | Disable } ]
[ { Show | Hide } ]
[ Active ]
id_num is an integer identifying one of the controls in the active dialog box.
title is a string representing the new title to assign to the control.
array_name is the name of an array variable; used to reset the contents of ListBox, MultiListBox, and PopupMenu controls.
value is the new value to associate with the specified control.
Restrictions
You cannot issue this statement through the MapBasic window.
Description
The Alter Control statement modifies one or more attributes of a control in the active dialog box; accordingly, the Alter Control statement should only be issued while a dialog box is active (for example, from within a handler procedure that is called by one of the dialog box controls). If there are two or more nested dialog boxes on the screen, the Alter Control statement only affects controls within the topmost dialog box.
The id_num specifies which dialog box control should be modified; this corresponds to the id_num parameter specified within the ID clause of the Dialog statement.
Each of the optional clauses (Title, Value, Enable/Disable, Hide/Show, Active) modifies a different attribute of a dialog box control. Note that all of these clauses can be included in a single statement; thus, a single Alter Control statement could change the name, the value, and the enabled/disabled status of a dialog box control.
Some attributes do not apply to all types of controls. For example, a Button control may be enabled or disabled, but has no value attribute.
The Title clause resets the text that appears on most controls (except for Picker controls and EditText controls; to reset the contents of an EditText control, set its Value). If the control is a ListBox, MultiListBox, or PopupMenu control, the Title clause can read the control's new contents from an array of string variables, by specifying a From Variable clause.
The Active keyword applies only to EditText controls. An Alter Control...Active statement puts the keyboard focus on the specified EditText control.
Use the Hide and Show keywords to make controls disappear or reappear.
To de-select all items in a MultiListBox control, use a value setting of zero. To add a list item to the set of selected MultiListBox items, issue an Alter Control statement with a positive integer value corresponding to the number of the list item.
You can use an Alter Control statement to modify the text that appears in a StaticText control. However, MapInfo Pro cannot increase the size of the StaticText control after it is created. Therefore, if you plan to alter the length of a StaticText control, you may want to pad it with spaces when you first define it. For example, your Dialog statement could include the following clause:
Control StaticText ID 1 Title "Message goes here" + Space$(30)
Example
The following example creates a dialog box containing two check boxes, an OK button, and a Cancel button. Initially, the OK button is disabled (grayed out). The OK button is only enabled if the user selects one or both of the check boxes.
Include "mapbasic.def"
Declare Sub Main
Declare Sub checker
Sub Main
Dim browse_it, map_it As Logical
Dialog
Title "Display a file"
Control CheckBox
Title "Display in a Browse window"
Value 0
Calling checker
ID 1
Into browse_it
Control CheckBox
Title "Display in a Map window"
Value 0
Calling checker
ID 2
Into map_it
Control CancelButton
Control OKButton
ID 3
Disable
If CommandInfo(CMD_INFO_DLG_OK) Then
' ... then the user clicked OK...
End If
End Sub
Sub checker
' If either check box is checked,
' enable the OK button; otherwise, Disable it.
If ReadControlValue(1) Or ReadControlValue(2) Then
Alter Control 3 Enable
Else
Alter Control 3 Disable
End If
End Sub