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.
Controls
DataWindow, EditMask, InkEdit, MultiLineEdit, SingleLineEdit, DropDownListBox,
and DropDownPictureListBox controls
Syntax
1 |
<span>editname</span>.<span>SelectText</span> ( <span>start</span>, <span>length</span> ) |
Argument |
Description |
---|---|
editname |
The name of the DataWindow, EditMask, |
start |
A long specifying the position at which |
length |
A long specifying the number of characters |
Return Values
Integer for DataWindow and list boxes, Long for
other controls.
Returns the number of characters selected.
If an error occurs, SelectText returns -1.
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.
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
This statement sets the insertion point at the end
of the text in the SingleLineEdit sle_name:
1 |
sle_name.<span>SelectText</span>(Len(sle_name.Text), 0) |
This statement selects the entire contents of the
SingleLineEdit sle_name:
1 |
sle_name.<span>SelectText</span>(1, Len(sle_name.Text)) |
The rest of these examples assume the MultiLineEdit mle_EmpAddress contains Boston
.
Street
The following statement selects the string ost
and
returns 3:
1 |
mle_EmpAddress.<span>SelectText</span>(2, 3) |
The next statement selects the string oston
and returns 12:
Street
1 |
mle_EmpAddress.<span>SelectText</span>(2, & |
1 |
Len(mle_EmpAddress.Text)) |
These statements select the string Bos
,
returns 3, and sets the focus to mle_EmpAddress so
that Bos
is highlighted:
1 |
mle_EmpAddress.<span>SelectText</span>(1, 3) |
1 |
mle_EmpAddress.SetFocus() |