vbdpss.hlp (Table of Contents; Topic list)
Article Q58213, Program 3
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 How to Empty (Flush) File And Keyboard Buffers in Basic - Q58213
 
 Code Example 3
 ______________
 
 Flushing a file buffer to disk from within a Visual Basic version 1.0
 for MS-DOS program can be done with one of the following two methods
 using MS-DOS Interrupt CALLs:
 
 1. Using MS-DOS version 3.3 or later, the MS-DOS Interrupt 21h with
    Function 68h commits the file buffer to disk.
 
 2. Using MS-DOS earlier than version 3.30, the MS-DOS Interrupt 21h
    with Function 45h creates a duplicate file handle, followed by a
    Interrupt 21h with Function 3Eh to close the duplicate file
    handle, which commits the file buffer to disk.
 
 Using Interrupt 21h with Function 68h 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 version 3.3 or later.
 
 The following program demonstrates how to perform this type of
 functionality. The "commit" subroutine in the program included below
 demonstrates Method 2, and the "commit330" subroutine in the program
 included below demonstrates Method 2.
 
 ' To try this example in VBDOS.EXE:
 ' 1. From the File menu, choose New Project.
 ' 2. Copy the code example to the Code window.
 ' 3. Press F5 to run the program.
 
 DECLARE SUB commit (filenum%)     ' For use with MS-DOS 2.10 & up.
 DECLARE SUB commit330 (filenum%)  ' For use with MS-DOS 3.30 & up.
 
 ' Use the following include file for Visual Basic 1.0 for MS-DOS:
 REM $INCLUDE: 'VBDOS.BI'
 
 CLS
 DIM SHARED inregs AS RegType      ' Define inregs of regtype.
 DIM SHARED outregs  AS RegType    ' Define outregs of regtype.
 
 '-----------------------------------------------------------
 PRINT "press any key to open file"
 SLEEP                             ' Wait for keyboard input.
 OPEN "b:stuff2" FOR RANDOM AS #1 LEN = 80
 PRINT "press a key to write to buffer"
 SLEEP
 a$ = "this and that"
 PUT #1, 1, a$                     ' Write buffer.
 
 '-----------------------------------------------------------
 PRINT "press any key to commit the buffer to disk"
 SLEEP                             ' Wait for keyboard input.
 CALL commit330(1)                 ' Commit buffer for file 1.
 
 '-----------------------------------------------------------
 PRINT "press any key to close file"
 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 21h to
 '                                        commit buffer.
 END SUB