Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>lbl_save() writes label definition to (.lbl) rlback.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Lbl_save()     Writes label definition to (.lbl)            Rlback.prg


Syntax:        Lbl_save(<lbl_file>, <dbf_file>, <mem_file>)

Argument:      <lbl_file> is the label file to save.

               <dbf_file> is the database file containing label line
               contents.

               <mem_file> is the memory file containing the label
               specifications.

Returns:       Returns true (.T.) is the save operation was successful.

Calls:         Num_2_word()

Notes:         . Label file name passed with extension.
               . File error number placed in file_error.


--------------------------------- Source Code ------------------------------

   FUNCTION LBL_SAVE

   PARAMETERS label_file, dbf_file, mem_file

   PRIVATE label_image, label_size, content_size, handle,;
      write_count, status, i, lbl_remark, lbl_height, lbl_width,;
      lbl_margin, lbl_lines, lbl_spaces, lbl_across

   label_size   = 1034        && size of label file.
   label_image  = ""          && holds modified label for write
                              && operation.
   content_size = 960         && content area of file holds 16
                              && 60-byte records.

   write_count = 0            && bytes written.
   handle      = 0
   i           = 0            && record counter.
   status      = .F.

   ** Create the label file **
   handle = FCREATE(label_file)

   ** Open ok? **
   file_error = FERROR()
   status = (file_error = 0)

   IF status
      ** Restore label dimension values **
      RESTORE ADDITIVE FROM &mem_file

      ** Build new file image. **
      label_image = CHR(2) + lbl_remark + CHR(lbl_height) + CHR(0);
                  + CHR(lbl_width) + CHR(0) + CHR(lbl_margin);
                  + CHR(0) + CHR(lbl_lines) + CHR(0) + CHR(lbl_spaces);
                  + CHR(0) + CHR(lbl_across) + CHR(0)

      ** Add contents fields to label file image **
      USE &dbf_file
      FOR i = 0 to (lbl_height - 1)
         label_image = label_image + contents
         SKIP
      NEXT
      CLOSE DATABASES

      ** Pad if needed **
      IF i < 16
         label_image = label_image + SPACE(content_size - (60 * i))
      ENDIF

      ** Label file signature, 1034th byte **
      label_image = label_image + CHR(2)

      ** Write new image to label file **
      write_count = FWRITE(handle, label_image, label_size)

      ** WRITE error? **
      IF write_count = 0
         file_error = -2
      ELSE
         file_error = FERROR()
      ENDIF

      ** Close file **
      IF !FCLOSE(handle)
         file_error = FERROR()     && write error detect may be covered up
      ENDIF                        && if done differently.

      status = (file_error = 0)

   ENDIF

   RETURN (status)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson