See Also Example
Applies To
Combo box, directory list box
Description
Indicates that the contents of a control have changed. How and when this event occurs varies with the control:
Combo box
changes the text in the text box portion of the control. Occurs only if the Style property is 0 (Dropdown Combo) or 1 (Simple Combo) and the user changes the text or you change the Text property from code.
Directory list box
changes the selected directory. Occurs when the user double-clicks a new directory or when you change the Path property from code.
Drive list box
changes the selected drive. Occurs when the user selects a new drive or when you change the Drive property from code.
Horizontal and vertical scroll bar
moves the scroll box portion of the scroll bar. Occurs when the user scrolls or when you change the Value property from code.
Label
changes the contents of the label. Occurs when a DDE link updates data or when you change the Caption property from code.
Picture box
changes the contents of the picture box. Occurs when a DDE link updates data or when you change the Picture property from code.
Text box
changes the contents of the text box. Occurs when the user changes the text or when you change the Text property from code.
Syntax
Sub ctlname_Change (Index As Integer)
Remarks
The argument Index uniquely identifies a control if it is in a control array A Change procedure can synchronize or coordinate data display among controls. For example, you can use a scroll bar's Change procedure to update the scroll bar's Value property setting in a text box. Or you might use a Change procedure to display data and formulas in a work area and results in another area.
Change procedures are also useful for updating properties in file-system controls. For example, you can update the Path property for a directory list box to reflect a change in a drive list box's Drive property.
Note A Change procedure can sometimes cause a cascading event . This occurs when the control's Change event alters the control's contentsfor example, by setting a property in code that determines the control's value, such as the Text property setting for a text box. To prevent a cascading event:
If possible, avoid writing a Change procedure for a control that alters the control's contents. If you do write such a procedure, be sure to set a flag variable that blocks out further changes while the current change is in progress.
Avoid creating two or more controls whose Change procedures affect each other
for example, two text boxes that update each other.
Also avoid using a MsgBox function or statement in this event for horizontal or vertical scroll bars.
Help:
KeyDown, KeyUp Events
KeyPress Event
LinkTopic Property
LostFocus Event
PathChange Event
PatternChange Event
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
The example displays the numeric setting of a horizontal scroll bar's Value property in a text box. To try this example, create a form with a text box and a horizontal scroll bar (set Min = 0, Max = 1000, LargeChange = 100, and SmallChange = 1). To try this example, paste the code into the Declarations section of a form that contains a horizontal scroll bar and a text box. Then press F5 and click the horizontal scroll bar.
Sub Form_Load ()
HScroll1.Min = 0 ' Set Minimum.
HScroll1.Max = 1000 ' Set Maximum.
HScroll1.LargeChange = 100 ' Set LargeChange.
HScroll1.SmallChange = 1 ' Set SmallChange.
End Sub
Sub HScroll1_Change ()
Text1.Text = HScroll1.Value
End Sub