Change, SelChange Event

Purpose

Indicates the contents of the current selection of a TextBox or RichEdit control have changed.

Syntax

Sub object_Change([index%])

Sub object_SelChange([index%])

object:TextBox, RichEdit Ocx
index:iexp (identifies a form or control if it's in a form or control array)

Description

The Change event procedure can synchronize or coordinate data display among controls. For example, you can use a Change event procedure to update the contents of another control. Or you can use a Change event procedure to display data and formulas in a work area and results in another area.

You can use the SelChange event to check the various properties that give information about the current selection (such as SelBold) so you can update buttons in a toolbar, for example.

Example

OpenW 1

Ocx TextBox TBox1 = "", 100, 10, 100, 24

TBox1.BorderStyle = 1

TBox1 = "This is a Test"

TBox1.FontBold = 0

TBox1.BackColor = RGB(224, 224, 224)

TBox1.ForeColor = RGB(255, 0, 0)

TBox1.SelStart = 3

TBox1.SelLength = 4

Do

Sleep

Loop Until Me Is Nothing

 

Sub TBox1_Change

Print "Change "; TBox1

EndSub

 

Sub TBox1_SelChange

Print "SelChange "; TBox1.SelText

EndSub

Remarks

A Change event procedure can sometimes cause a cascading event. This occurs when the control's Change event alters the control's contents, for example, by setting a property in code that determines the control's value, such as the Text property setting for a TextBox control. To prevent a cascading event avoid creating two or more controls whose Change event procedures affect each other, for example, two TextBox controls that update each other during their Change events.

See Also

TextBox, RichEdit

{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}