SelectTextWord

Description

Selects the word containing the insertion point in a RichTextEdit control.

Applies to

RichTextEdit and DataWindow controls

Syntax

rtename.SelectTextWord ( )

Argument

Description

rtename

The name of the RichTextEdit or DataWindow control in which you want to select a word. The DataWindow object in the DataWindow control must be a RichTextEdit DataWindow.


Return value

Integer.

Returns the number of characters selected if it succeeds and -1 if a word cannot be selected or an error occurs.

Usage

A word is any group of alphanumeric characters. A word can include underscores and single quotes but does not include punctuation and special characters such as $ or #. If punctuation or special characters follow the selected word, they are not selected.

If the character after the insertion point is a space, punctuation, special character, or end-of-line mark, SelectTextWord does not select anything and returns -1.

Examples

The following statement selects the word containing the insertion point:

rte_1.SelectTextWord()

This example selects the word at the insertion point. If there is no word, it increments the position until it finds a word. It checks when it reaches the end of a line and wraps to the next line as it looks for a word. If this script is assigned to a command button and the button is clicked repeatedly, you step through the text word by word:

integer li_rtn
long llstart, lcstart, ll_lines, ll_chars
 
ll_lines = rte_1.LineCount()
ll_chars = rte_1.LineLength()
 
li_rtn = rte_1.SelectTextWord()
 
// -1 if a word is not found at the insertion point
   DO WHILE li_rtn = -1
 
      // Get the position of the cursor
      rte_1.Position(llstart, lcstart)
 
      // Increment by 1 to look for next word
      lcstart += 1
      // If at end of line move to next line
      IF lcstart >= ll_chars THEN
         lcstart = 1  // First character
         llstart += 1 // next line
 
         // If beyond last line, return
         IF llstart > ll_lines THEN
            RETURN 0
         END IF
      END IF
 
      // Set insertion point
      rte_1.SelectText(llstart, lcstart, 0, 0)
      // In case it's a new line, get new line length
      // Can't do this until the ins pt is in the line
      ll_chars = rte_1.LineLength( )
 
      // Select word, if any
      li_rtn = rte_1.SelectTextWord()
LOOP
 
// Add code here to process the word (for example,
// passing the word to a spelling checker)

See also

SelectedText

SelectText

SelectTextAll

SelectTextLine