Load / Save ANY array

Another Load / Save array sample, this time for ANY array.

This sample load an external ANY array from a text file to the GRID and upon exit save it to the file.

For manipulating on the array into program we are using a GRID control.

All critics and suggestions are welcome.

Download source ( .prg, hbp, txt ) files.

Advertisements

SP_WRITEFILE

WRITEFILE()

  Short:
  ------
  WRITEFILE() Writes a line or lines  to a text file

  Returns:
  --------
  nothing

  Syntax:
  -------
  Writefile(cFileName|n|FileHandle,cText|aText)

  Description:
  ------------
  Writes line(s) of text with CR LF to a file
  referenced either as a file handle <nFileHandle> or a file
  name <cFileName>.

  Writes either a single line contained in <cText> or all of the
  contents of array <aText> to the file.

  Examples:
  ---------
   1. WRITEFILE('ERROR.TXT','THERE WAS AN ERROR')

   2. aErrors := array(3)
      aErrors[1] = 'There was an error'
      aErrors[2] = 'Error # 61765  '
      aErrors[3] = dtoc(date)
      writefile('ERROR.TXT',aErrors)

   3. nHandle := fopen("error.txt",1)
      aErrors := array(3)
      aErrors[1] = 'There was an error'
      aErrors[2] = 'Error # 61765  '
      aErrors[3] = dtoc(date)
      writefile(nHandle,aErrors)

  Notes:
  -------
  If a filename is passed, the file is opened and
  closed by the function.

  If a file handle is passed, the file is left open. If
  the file does not exist, it is created.

  PREVIOUSLY AN ARRAY NAME WAS PASSED. THIS MUST NOW BE
  AN ARRAY.

  Source:
  -------
  S_WRITEF.PRG

 

SP_SFREADLINE

()

  Short:
  ------
  SFREADLINE() Reads in text up to the next CRLF in a text file

  Returns:
  --------
  <cLine> => line read in

  Syntax:
  -------
  SFREADLINE(nHandle)

  Description:
  ------------
  Reads in text up to the next CRLF in a text file. The
  pointer is moved back to the starting position when done. To move to a
  new line, use  FMOVE2PRIOR() or FMOVE2NEXT().

  Examples:
  ---------
   nHandle := fopen("Report.doc")

   ?sfreadline(handle)
   while fmove2next(handle)
     ?sfreadline(handle)
   end

  Source:
  -------
  S_FREADL.PRG

 

SP_FMOVE2PRIOR

FMOVE2PRIOR()

  Short:
  ------
  FMOVE2PRIOR() Moves to beginning of previous CRLF delimited
  line in a text file

  Returns:
  --------
  <lSuccess> => for success

  Syntax:
  -------
  FMOVE2PRIOR(nHandle)

  Description:
  ------------
  Moves pointer in a text file <nHandle> opened with
  FREAD() to the beginning if the next CRLF delimited line in the
  file. Returns .f. if unable to.

  Examples:
  ---------
   FMOVE2PRIOR(handle)

   ?FREADLINE(handle)

  Source:
  -------
  S_FM2P.PRG

 

SP_FMOVE2NEXT

FMOVE2NEXT()

  Short:
  ------
  FMOVE2NEXT() Move to beginning of next line in a text file

  Returns:
  --------
  <lSuccess> => success in doing so

  Syntax:
  -------
  FMOVE2NEXT(nHandle)

  Description:
  ------------
  Moves pointer in text file <nHandle> to beginning of
  next line.

  Presuming lines end in CRLF. Returns <expL> for
  success. End of file would return .f.

  Examples:
  ---------

   // this will list off the text file REPORT.LST to the  screen

   h := fopen("report.lst")
   ?SFREADLINE(h)
   while  FMOVE2NEXT(h)
    ?SFREADLINE(h)
   end

  Source:
  -------
  S_FM2N.PRG

 

SP_FILEREAD

FILEREAD()

  Short:
  ------
  FILEREAD() Lists a text file of unlimited size

  Returns:
  --------
  nothing

  Syntax:
  -------
  FILEREAD([nTop,nLeft,nBottom,nRight],[cFileName],[cTitle],;
            [lSearch],[lMark])

  Description:
  ------------
  Lists text file [cFileName] of unlimited size in a
  programmer definable window of dimensions [nTop..nRight]

  Allows up down right left scrolling. Use this for
  reports or output sent to a disk file.

  If [cFileName]  is not passed, a box asks for the
  filespec and then allows a picklist of files of that spec. If
  [cFileName] is passed as a wildcard (i.e. "*.DOC"). a picklist
  of files of that spec is presented.

  If [nTop..nRight] are not passed, a default window of
  dimensions 2,2,22,78 is used.

  [cTitle] is an optional title. This overrides the
  default which is the file name.

  [lSearch] is a switch to allow text searches. Default
  is True

  [lMark] is a switch to allow block marking (with Copy
  to File or Print) Default is True.

  Examples:
  ---------
   REPORT FORM summary TO summary.txt
   FILEREAD(2,2,22,78,"SUMMARY.TXT","Summary File")

  Notes:
  -------
  Fileread() will use SET DEFAULT if no path is
  specified.

  Source:
  -------
  S_FILER.PRG

 

Format of xBase Files

xBase File Format Description