[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
##############################################################################
###+-----------+##############################################################
#+-| FB_OPEN() |---------------------------------------------------------+####
#| +-----------+ Opens any type of file for reading,writing or appending |####
#+-----------------------------------------------------------------------+####
##############################################################################
##############################################################################
#+--| Summary |----------------+##############################################
#| #INCLUDE fileio.hdr |##############################################
#+-----------------------------+##############################################
##############################################################################
##############################################################################
#+--| Syntax |---------------------------------------------------------+######
#| FUNCTION LOGICAL fb_open PROTOTYPE |######
#| PARAMETERS UINT handle, CONST CHAR filename VALUE INT mode |######
#+---------------------------------------------------------------------+######
##############################################################################
##############################################################################
##########+---| Description |---------------------------------------+#########
##########| The fb_open() function opens any type of file - ASCII, |#########
##########| text, binary - for reading, writing or appending |#########
##########| depending upon mode. If the file filename can not be |#########
##########| opened, then fb_open() returns FALSE. |#########
##########| ------------------------------------------------------- |#########
##########| When the file is opened, fb_open() initializes the |#########
##########| parameter handle. The variable handle must be used on |#########
##########| all subsequent accesses to the file. |#########
##########| ------------------------------------------------------- |#########
##########| The fb_read() and fb_write() allow reading and writing |#########
##########| to the predefined DOS file handles. These handles do |#########
##########| NOT need to be opened by fb_open() prior to use. The |#########
##########| header file fileio.hdr contains defines for the DOS |#########
##########| standard file handles. see fb_read() for more details. |#########
##########| ------------------------------------------------------- |#########
##########| To close the file associated with handle, use the |#########
##########| fb_close procedure. |#########
##########| ------------------------------------------------------- |#########
##########| The parameter mode specifies how the file is to be |#########
##########| treated. refer to BINARY OPEN MODES TABLE. |#########
##########+---------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 1 |-------------------------------------------+#########
#########| * Print the field name and type from header. |#########
#########| |#########
#########| #include fileio.hdr |#########
#########| #include string.hdr |#########
#########| |#########
#########| PROCEDURE force_main |#########
#########| PARAMETERS CONST CHAR filename |#########
#########| VARDEF |#########
#########| BYTE b[32] |#########
#########| UINT h |#########
#########| CHAR fname BASED b |#########
#########| ENDDEF |#########
#########| |#########
#########| IF .NOT. fb_open( h, ltrim(filename), &B_READ ) |#########
#########| ? "Can not open " + filename |#########
#########| QUIT |#########
#########| ENDIF |#########
#########| fb_read( h, b[], 32 ) && read 1st 32 bytes |#########
#########| |#########
#########| DO WHILE .NOT. fb_eof( h ) |#########
#########| fb_read( h, b[], 32 ) |#########
#########| IF b[0] = 0xd && 0D marks the end |#########
#########| EXIT |#########
#########| ENDIF |#########
#########| ? fname, chr( b[11] ) |#########
#########| ENDDO |#########
#########| fb_close( h ) |#########
#########| ENDPRO |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 2 |-------------------------------------------+#########
#########| * Change a damaged dBASE header so it indicates |#########
#########| * that the database contains a memo file. |#########
#########| |#########
#########| VARDEF |#########
#########| BYTE memo_indicator |#########
#########| ENDDEF |#########
#########| |#########
#########| IF fb_open( h, "test.dbf", &B_READ_WRITE ) |#########
#########| fb_read( h, memo_indicator, 1 ) |#########
#########| IF memo_indicator = 80 |#########
#########| ? "Memo is associated with database." |#########
#########| RETURN |#########
#########| ENDIF |#########
#########| fb_seek( h, &B_BEGIN, 0 ) && goto BOF |#########
#########| memo_indicator = 80 |#########
#########| fb_write( h, memo_indicator, 1 ) |#########
#########| fb_close( h ) |#########
#########| ENDIF |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 3 |-------------------------------------------+#########
#########| * If a file does not exist, create it during |#########
#########| * the open. |#########
#########| |#########
#########| fb_open( handle, filename, &B_CREAD_WRITE ) |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 4 |-------------------------------------------+#########
#########| * Create a "COPY TO" command. |#########
#########| |#########
#########| FUNCTION LOGICAL copy_to |#########
#########| PARAMETERS CONST CHAR source, CONST CHAR destination |#########
#########| VARDEF |#########
#########| UINT sh, dh |#########
#########| BYTE b[4096] && 4096 copy buffer |#########
#########| UINT transfer_bytes |#########
#########| ENDDEF |#########
#########| |#########
#########| IF .NOT. fb_open( sh, source, &B_READ ) |#########
#########| RETURN .F. |#########
#########| ENDIF |#########
#########| |#########
#########| IF .NOT. fb_open( dh, destination, &B_CWRITE ) |#########
#########| fb_close( sh ) |#########
#########| RETURN .F. |#########
#########| ENDIF |#########
#########| |#########
#########| REPEAT |#########
#########| transfer_bytes = fb_read( sh, b[], 4096 ) |#########
#########| fb_write( dh, b[], transfer_bytes ) |#########
#########| UNTIL .T. |#########
#########| |#########
#########| fb_close( sh ) |#########
#########| fb_close( dh ) |#########
#########| RETURN .T. |#########
#########| ENDPRO |#########
#########+----------------------------------------------------------+#########
##############################################################################
See Also:
fb_close
fb_eof()
fb_read()
fb_seek()
fb_write()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson