PreviousNextIndex

OVERLAY statement

Inserts content from a specified expression into a field or variable replacing existing characters, bytes, or columns.

Syntax

OVERLAY ( target , position [ , length [ , type ] ] ) = expression 

target
position
length
type
expression
Example

The r-replc1.p procedure lets you search for, and replace text strings in a paragraph in a window. When you run the procedure, you see the paragraph, which is an array with an extent of five. You also see a prompt. Enter the text string you want the system to search for, and the new text you want in its place. The procedure searches the paragraph, one line at a time, for the text you entered. The procedure uses the OVERLAY statement to replace the string of old text with the string of new text. The procedure also determines the length of the old text and the new text.

r-replc1.p
DEFINE VARIABLE chktext  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ix       AS INTEGER   NO-UNDO. 
DEFINE VARIABLE chkndx   AS INTEGER   NO-UNDO. 
DEFINE VARIABLE ndx      AS INTEGER   NO-UNDO. 
DEFINE VARIABLE old-text AS CHARACTER NO-UNDO. 
DEFINE VARIABLE new-text AS CHARACTER NO-UNDO. 
DEFINE VARIABLE max-len  AS INTEGER   NO-UNDO. 
DEFINE VARIABLE comment  AS CHARACTER NO-UNDO FORMAT "x(49)" EXTENT 5 
  INITIAL ["You are probably interested in OpenEdge because", 
    "you have a lot of information to organize.  You", 
    "want to get at the information, add to it, and", 
    "change it, without a lot of work and aggravation.", 
    "You made the right choice with OpenEdge." ]. 
DISPLAY comment WITH CENTERED FRAME comm NO-LABELS 
  TITLE "Why You Chose OpenEdge" ROW 4. 
REPEAT: 
  SET old-text LABEL "Enter text to search for" 
    new-text LABEL "Enter text to replace with" 
    WITH FRAME replace SIDE-LABELS CENTERED. 
  max-len = MAXIMUM(LENGTH(old-text), LENGTH(new-text)). 
  DO ix = 1 TO 5: 
    ndx = 1. 
    DO ndx = 1 TO LENGTH(comment[ix]): 
      chktext = SUBSTRING(comment[ix], ndx). 
      chkndx = INDEX(chktext, old-text). 
      IF chkndx <> 0 THEN DO: 
        ndx = ndx + chkndx - 1. 
        OVERLAY(comment[ix], ndx, max-len, "CHARACTER") = new-text. 
        ndx = max-len. 
      END. 
    END. 
    DISPLAY comment[ix] WITH FRAME comm. 
  END. 
END. 

Notes
See also

SUBSTRING function, SUBSTRING statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex