ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Sellength, SelStart, and Seltext Properties Example
                        ◄Example►                ◄Contents►  ◄Index►  ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example allows the user to specify search text, searches the text, and
' if the text is found, selects it.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Choose New Form from the File menu to create a form with a wide text box
' 3. Press Alt+F4 to return to the programming environment
' 4. Copy the code example below to the form module
' 5. Press F5 to run the example
 
 SUB Form_Click ()
     DIM Search$                              ' Text to search for
     DIM Where%                               ' Position where found
     ' Get search string from user.
     Search$ = INPUTBOX$("Enter text to be found:")
     Where% = INSTR(Text1.Text, Search$)      ' Find string in text
     IF Where% THEN                           ' If found...
          Text1.SelStart = Where% - 1         ' Set start of selection
          Text1.SelLength = LEN(Search$)      ' Set length of selection
     ELSE
          MSGBOX "String not found."          ' Notify user
     END IF
 END SUB
 
 SUB Form_Load ()
     Text1.Text = "Two of the peak human experiences"
     Text1.Text = Text1.Text + " are good food and classical music."
 END SUB