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>write_field() write a field element to the fields area rlback.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Write_field()   Write a field element to the fields area    Rlback.prg


Syntax:        Write_field()

Returns:       True (.T.) if the write operation was successful.

Calls:         Write_expr(), Num_2_word()

Notes:         . Called by FRM_SAVE().
               . Updates fields_offset, lengths_offset, offsets_offset,
                 last_expr.
               . File error number placed in file_error.


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

   FUNCTION WRITE_FIELD

   PRIVATE status, write_item, write_len, write_count, cnts_offset,;
     hdr_offset

   status      = .F.
   write_item  = ""
   write_len   = 0
   write_count = 0
   cnts_offset = 65535
   hdr_offset  = 65535

   ** Write Contents **
   cnts_offset = WRITE_EXPR(trim(contents), .F.)

   ** WRITE ok? **
   IF cnts_offset != -1

      ** Write Header **
      hdr_offset = WRITE_EXPR(trim(header), .T.)

      ** WRITE ok? **
      IF hdr_offset != -1

         ** Seek to the next free FIELDS area **
         fields_offset = fields_offset + 12
         FSEEK(handle, fields_offset)

         ** SEEK ok? **
         file_error = FERROR()
         IF file_error = 0

            write_item = NUM_2_WORD(width) +;
                            replicate(CHR(0), 3) +;
                            totals +;
                            NUM_2_WORD(decimals) +;
                            NUM_2_WORD(cnts_offset) +;
                            NUM_2_WORD(hdr_offset)
            write_len = LEN(write_item)

            ** Write the FIELDS info **
            write_count = FWRITE(handle, write_item, write_len)

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

            ** WRITE ok? **
            status = (file_error = 0)

         ENDIF
      ENDIF
   ENDIF

   RETURN (status)

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