Accept User Input and Display the Values of Controls on a Form
The following example demonstrates the values that the different types of controls can have by displaying the
Value
property of a selected control. The user chooses a control by pressing TAB or by clicking on the control. Depending on the type of control, the user can also specify a value for the control by typing in the text area of the control, by clicking one or more times on the control, or by selecting an item, page, or tab within the control. The user can display the value of the selected control by clicking the appropriately labeled
CommandButton
.
To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the
Open
event will activate. Make sure that the form contains:
SubCommandButton1_Click()SetTextBox1=Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")SetForm=Item.GetInspector.ModifiedFormPages("P.2")TextBox1.Text="Value of "&Form.ActiveControl.Name&" is "&Form.ActiveControl.ValueEndSubSubItem_Open()SetCommandButton1=Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")SetTextBox1=Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1")SetComboBox1=Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1")SetListBox1=Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")SetCheckBox1=Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1")SetToggleButton1=Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")SetTextBox2=Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2")CommandButton1.Caption="Get value of current control"CommandButton1.AutoSize=TrueCommandButton1.TakeFocusOnClick=FalseCommandButton1.TabStop=FalseTextBox1.AutoSize=TrueFori=0To10ComboBox1.AddItem"Choice "&(i+1)ListBox1.AddItem"Selection "&(100-i)CheckBox1.TripleState=TrueToggleButton1.TripleState=TrueTextBox2.Text="Enter text here."EndSub