See Also Example
Combo box, directory list box, drive list box , horizontal scroll bar , label , picture box , text box , vertical scroll bar .
Indicates that the contents of a control have changed. How and when this event occurs varies with the control:
Combo boxchanges 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 boxchanges the selected directory. Occurs when the user double-clicks a new directory or when you change the Path property from code.
Drive list boxchanges the selected drive. Occurs when the user selects a new drive or when you change the DriveYLV8AS property from code.
Horizontal and vertical scroll barmoves the scroll box portion of the scroll bar. Occurs when the user scrolls or when you change the Value property from code.
Labelchanges the contents of the label. Occurs when a DDE link updates data or when you change the Caption property from code.
Picture boxchanges the contents of the picture box. Occurs when a DDE link updates data or when you change the Picture property from code.
Text boxchanges the contents of the text box. Occurs when the user changes the text or when you change the Text property from code.
Sub ctlname_Change (Index As Integer)
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 otherfor 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.
KeyDown, KeyUp Events
Chapter 3, "Creating and Using Controls"
Change Event Example
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.
Sub HScroll1_Change ()
Text1.Text = HScroll1.Value