Functions and Directives

Function MlPos() Foundation

Determines starting position of the specified line in a formatted character string.

Syntax
MlPos( <cString>  , ;
       <nLineLen> , ;
       <nRow>     , ;
      [<nTabSize>], ;
      [<lWrap>]     ) --> nPosition
Parameters
<cString>
<cString> is a character string which may contain formatting characters like tab (Chr(9)) or return (Chr(13)+Chr(10)).
<nLineLen>
<nLineLen> is an integer numeric value specifying the maximum length of a line in <cString>.
<nRow>
<nRow> specifies the line whose start position is to be found. The line counter begins with the value one.
<nTabSize>
The tab size is specified by <nTabSize>. The default value is four characters per tab. The tab value must be smaller than <nLineLen> - 1.
<lWrap>
The logical value for <lWrap> specifies whether automatic word wrap is taken into consideration. The default value is .T. (true) which indicates that automatic word wrapping is taken into consideration. When the value .F. (false) is specified, word wrapping is not taken into consideration.
Return

MlPos() returns the position of the first character in the row <nRow> within <cString> as an integer numeric value. When <nRow> is greater than the entire number of rows in <cString>, Len(<cString>) is returned.

Description

The memo function MlPos() is similar to the function MlCtoPos() and returns an exact position within a character string which may contain formatting characters. MlPos() differs from MlCtoPos() in that it uses only row position and returns the start position of the indicated row.

Examples
MlPos()
// In this example, MlPos() is used to send the contents of a file 
// page by page to the printer along with page headers which 
// include the page numbers as well as the date and time. 

PROCEDURE Main 
   LOCAL nLineLen := 55 
   LOCAL nPageLen := 50 
   LOCAL nPageNum := 1 
   LOCAL nPos 

   cString = MemoRead("TEXTFILE.TXT") 
   SET MARGIN TO 8 

   DO WHILE Len( cString ) > 0 
      SET PRINTER OFF 
      SET CONSOLE ON 

      DO WHILE .NOT. IsPrinter() 

         @ 0,0 SAY "Printer not ready" 

         Inkey(1) 
         IF LastKey()==K_ESC 

            @ 0,0 SAY "Printing was aborted" 

            cString := "" 
            EXIT 
         ENDIF 
      ENDDO 


      @ 0,0 SAY "Printing page No:" 

      ?? nPageNum 

      SET PRINTER ON 
      SET CONSOLE OFF 
      ? PadL( "Page: "+Str(nPageNum,8), nLineLen ) 
      ? PadL( "Date: "+DtoC(Date())   , nLineLen ) 
      ? PadL( "Time: "+Time()         , nLineLen ) 

      nPos := MlPos( cString, nLineLen, nPageLen ) 

      ? SubStr( cString, 1, nPos - 1 ) 
      cString := SubStr( cString, nPos ) 

      nPageNum ++ 
      EJECT 

   ENDDO 
   SET MARGIN TO 
   SET PRINTER OFF 
   SET CONSOLE ON 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.