JavaScript Editor js editor     Web development 

Main Page

File: ...\Samples\Solution\Controls\TXT_EDT\Text.scx

This sample illustrates using the SelStart, SelLength, and SelText properties of an edit box to manipulate the text at run time. The sample also counts the characters, words, and paragraphs in a text file and makes it possible for a user to search for a string in a text file.

Formatting Text

The following code is included in the Click event of the button that formats selected text to uppercase:

В Copy Code
lo = THIS.Parent.edtText
lnOldStart = lo.SelStart
lnOldLength = lo.SelLength
lo.SelText = UPPER(lo.SelText)
lo.SelStart = lnOldStart
lo.SelLength = lnOldLength

If you want to specify the font attributes of selected sections of text, use a RichText control.

Searching for Text

After getting the text to search for, the following code loops through all the text in the edit box, comparing it to the target string:

В Copy Code
llKeepLooking = .T.
DO WHILE llKeepLooking
  FOR i = lnStart TO LEN(loEDT.Value)
    loEDT.SelStart = i
     loEDT.SelLength = lnLen
    IF loEDT.SelText = ALLTRIM(loCBO.Text) OR ;
         (!llCaseSensitive AND ;
         (UPPER(loEDT.SelText) = UPPER(ALLTRIM(loCBO.Text))))
      llFound = .T.
      llKeepLooking = .F.
  IF !llFound
    lnChoice=MESSAGEBOX("Search string not found.", ;
    IF lnChoice = 6 && Yes
      llKeepLooking = .T.
      lnStart = 0
      llKeepLooking = .F.
Be sure to set the form's LockScreen property to true (.T.) before searching and false (.F.) after searching. Otherwise, the form will repaint every time the SelStart property of the edit box is changed.

See Also

JavaScript Editor js editor     Web development