Microsoft KB Archive/43267

= How to Flush File Buffers from within a Basic Program =

Article ID: 43267

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS

-



This article was previously published under Q43267



SUMMARY
The following information applies to QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b, and to Microsoft Basic PDS Version 7.00.

Flushing a file buffer to disk from within a Basic program can be done with one of the following two methods using MS-DOS Interrupt CALLs:


 * 1) Using MS-DOS Version 3.30 or later, the MS-DOS Interrupt 21 Hex with Function 68 Hex commits the file buffer to disk.
 * 2) Using MS-DOS earlier than Version 3.30, the MS-DOS Interrupt 21 Hex with Function 45 Hex creates a duplicate file handle, followed by a Interrupt 21 Hex with Function 3E Hex to close the duplicate file handle, which commits the file buffer to disk.

Using Interrupt 21 Hex with Function 68 Hex has the advantage of not failing due to an insufficient number of file handles, or not risking losing control of the file in network environments. Its disadvantage is its limitation to MS-DOS 3.30 or later.



Code Example
DECLARE SUB commit (filenum%)    'for use with DOS 2.10 & up DECLARE SUB commit330 (filenum%)  'for use with DOS 3.30 & up

'The INCLUDE file name below would be 'QBX.BI' in the Basic PDS 7.00 '$INCLUDE: 'QB.BI'               'include file with regtype structure

CLS DIM SHARED inregs AS RegType     'define inregs of regtype DIM SHARED outregs AS RegType    'define outregs of regtype

'--- PRINT &quot;press any key to open file&quot; SLEEP                            'wait for keyboard input OPEN &quot;b:stuff2&quot; FOR RANDOM AS #1 LEN = 80 PRINT &quot;press a key to write to buffer&quot; SLEEP a$ = &quot;this and that&quot; PUT #1, 1, a$                    'Write buffer

'--- PRINT &quot;press any key to commit the buffer to disk&quot; SLEEP                            'wait for keyboard input CALL commit330(1)                'commit buffer for file 1

'--- PRINT &quot;press any key to close file&quot; SLEEP CLOSE 1 END

SUB commit (filenum%) inregs.ax = &H4500               'set funct 45H duplicate handle inregs.bx = FILEATTR(filenum%, 2) 'set file handle to duplicate CALL interrupt(&H21, inregs, outregs) 'call int 21H function 45H inregs.ax = &H3E00               'set function 3EH close file inregs.bx = outregs.ax           'set duplicated handle to close CALL interrupt(&H21, inregs, outregs) 'call int 21H function 3EH END SUB

SUB commit330 (filenum%) inregs.ax = &H6800               'function 68h inregs.bx = FILEATTR(filenum%, 2) 'place file handle in register BX inregs.flags = &H0               'initialize flag values CALL interrupt(&H21, inregs, outregs) 'call interrupt 21 to '                                       commit buffer END SUB

Additional query words: QuickBas BasicCom

Keywords: KB43267

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.