Freigeben über


MLINE( ) Function

Returns a specific line from a memo field as a character string.

MLINE(MemoFieldName, nLineNumber [, nNumberOfCharacters])

Return Values

Character

Parameters

  • MemoFieldName
    Specifies the name of the memo field from which MLINE( ) returns a line. If the memo field is in a table open in a noncurrent work area, preface the memo field name with a period and the table alias.

  • nLineNumber
    Specifies the number of the line to be returned from the memo field. An empty string is returned if nLineNumber is negative, 0, or greater than the number of lines in the memo field.

  • nNumberOfCharacters
    Specifies the number of characters from the beginning of the memo field after which MLINE( ) returns the specified line.

    The _MLINE system variable is typically used for nNumberOfCharacters. _MLINE is automatically adjusted each time MLINE( ) is called.

    In recursive procedures that return lines from large memo fields, you can obtain the best performance by including _MLINE as nNumberOfCharacters.

Remarks

MLINE( ) trims any trailing spaces from the line specified with nLineNumber.

The length and number of the lines in a memo field are determined by the current value of SET MEMOWIDTH (the default line length is 50 characters). If a carriage return is encountered, no additional characters are returned. The current _WRAP setting determines how the memo field line is displayed.

When searching a memo field for a character string, you can use ATLINE( ) or ATCLINE( ) to return the line number of the line in which the character string is found. Use this line number in MLINE( ) to return the contents of the line from the memo field.

Example

In the following example, two methods are used to return lines from a memo field. Two loops use MLINE( ) to return lines from the memo field. Note the improvement in performance in the second loop when the system variable _MLINE is used in MLINE( ).

CLEAR
SET TALK OFF
SET MEMOWIDTH TO 50
CLOSE DATABASES
CREATE TABLE tmemo (name c(10), notes m)
APPEND BLANK                  && Add a record
WAIT WINDOW 'Filling memo field - takes several seconds' NOWAIT

** Fill the memo field ** FOR gnOuterLoop = 1 TO 5 && loop 5 times FOR gnAlphabet = 65 TO 75 && letters A to H REPLACE notes WITH REPLICATE(CHR(gnAlphabet), 10) ; + CHR(13) ADDITIVE NEXT NEXT

** Display all lines from the memo field **

STORE MEMLINES(notes) TO gnNumLines   && Number of lines in memo field
STORE SECONDS( ) TO gnBegin      && Beginning time
FOR gnCount = 1 TO gnNumLines   && Loop for # of lines in memo field
   ? MLINE(notes, gnCount)      && Display each line
NEXT
? STR(SECONDS( ) - gnBegin, 4, 2) + ' seconds'   && Total time

_** Preferable method using MLINE in MLINE( ) ** ** Display all lines from the memo field **

WAIT 'Press a key to see the preferred method' WINDOW
CLEAR
STORE 0 TO _MLINE             && Reset _MLINE to zero
STORE SECONDS( ) TO gnBegin      && Beginning time
FOR count = 1 TO gnNumLines      && Loop for # of lines in memo field
   ? MLINE(notes, 1, _MLINE)      && Display each line
NEXT
? STR(SECONDS( ) - gnBegin, 4, 2) + ' seconds'   && Total time
SET TALK ON
CLOSE DATABASES
ERASE tmemo.dbf
ERASE tmemo.fpt

See Also

ALINES( ) | ATCLINE( ) | ATLINE( ) | COPY MEMO | MEMLINES( ) | _MLINE | MODIFY MEMO | SET MEMOWIDTH | _WRAP