DECLARE FUNCTION SetFocus LIB "USER32" ALIAS "SetFocus" (HWnd AS LONG) AS LONG
DECLARE SUB Search

CREATE Form AS QFORM
  Caption = "Form"
  Width = 320
  Height = 200
  Center
  CREATE Rich AS QRICHEDIT
    Left = 60
    Top = 31
    Height = 50
    AddStrings "noise one noise"
    AddStrings "noise two noise"
    AddStrings "noise three noise"
    SelStart = 0
    Scrollbars = 3
    HideSelection = 1
  END CREATE
  CREATE Poor AS QEDIT
    Left = 90
    Top = 90
    Text = "Type word then ENTER"
  END CREATE
  CREATE Invisible AS QBUTTON
    Top = 120
    Left = 110
    Caption = "Search"
    Default = 1  'no ding
    OnClick = Search
  END CREATE
  ShowModal
END CREATE

SUB Search
DEFLNG start
  where = INSTR(start,Rich.Text,Poor.Text)
  IF where <> 0 THEN
    SetFocus(Rich.Handle)
    Rich.SelStart = where - 1
    Rich.SelLength = LEN(Poor.Text)  'comment this out if you want cursor only
    start = where + LEN(Poor.Text)
  ELSE
    SHOWMESSAGE "No more instances of " + Poor.Text
    start = 0
  END IF
END SUB
