SelectText

Selects text in an editable control.

To select text in

Use

Any editable control, other than a RichTextEdit

Syntax 1 For editable controls (except RichTextEdit)

A RichTextEdit control or a DataWindow whose object has the RichTextEdit presentation style

Syntax 2 For RichTextEdit controls and presentation styles


Syntax 1 For editable controls (except RichTextEdit)

Description

Selects text in an editable control. You specify where the selection begins and how many characters to select.

Applies to

DataWindow, EditMask, MultiLineEdit, SingleLineEdit, DropDownListBox, and DropDownPictureListBox controls

Syntax

editname.SelectText ( start, length )

Argument

Description

editname

The name of the DataWindow, EditMask, MultiLineEdit, SingleLineEdit, DropDownListBox, or DropDownPictureListBox control in which you want to select text.

start

A long specifying the position at which you want to start the selection.

length

A long specifying the number of characters you want to select. If length is 0, no text is selected but PocketBuilder moves the insertion point to the location specified in start.

Returns

Long. Returns the number of characters selected. If an error occurs, SelectText returns -1. If any argument’s value is null, SelectText returns null.

Usage

If the control does not have the focus when you call SelectText, then the text is not highlighted until the control has focus. To set focus on the control so that the selected text is highlighted, call the SetFocus function.

NoteHow much to select When you want to select all the text of a line edit or select the contents from a specified position to the end of the edit, use the Len function to obtain the length of the control’s text.

To select text in a DataWindow with the RichTextEdit presentation style, use Syntax 2.

Examples

Example 1

This statement sets the insertion point at the end of the text in the SingleLineEdit sle_name:

sle_name.SelectText(Len(sle_name.Text), 0)

Example 2

This statement selects the entire contents of the SingleLineEdit sle_name:

sle_name.SelectText(1, Len(sle_name.Text))

Example 3

The rest of these examples assume the MultiLineEdit mle_EmpAddress contains Boston Street.

The following statement selects the string ost and returns 3:

mle_EmpAddress.SelectText(2, 3)

Example 4

The next statement selects the string oston Street and returns 12:

mle_EmpAddress.SelectText(2, &

		Len(mle_EmpAddress.Text))

Example 5

These statements select the string Bos, returns 3, and sets the focus to mle_EmpAddress so that Bos is highlighted:

mle_EmpAddress.SelectText(1, 3)

mle_EmpAddress.SetFocus()

See also


Syntax 2 For RichTextEdit controls and presentation styles

Description

Selects text beginning and ending at a line and character position in a RichTextEdit control.

Applies to

RichTextEdit and DataWindow controls

Syntax

rtename.SelectText ( fromline, fromchar, toline, tochar { band } )

Returns

Long. Returns the number of characters selected. If an error occurs it returns -1. If any argument’s value is null, SelectText returns null.