Open Existing File
QuickBasic
' DOS 2+ - OPEN - OPEN EXISTING FILE
'$INCLUDE: 'qb.bi'
DIM filename AS STRING
DIM Inregs AS RegTypeX
DIM outregs AS RegTypeX
' need to exist
filename = "C:\INT\123.txt" + CHR$(0)
Inregs.DS = VARSEG(filename)
Inregs.DX = SADD(filename)
' DOS interrupt with sub-function &H3D
' AH - &H3D
' AL - access and sharing modes
' 2-0 access mode: 000 read only
' 001 write only
' 010 read/write
' 3 reserved (0)
' 6-4 sharing mode (DOS 3.0+): 000 compatibility mode
' 001 "DENYALL" prohibit both read and write access by others
' 010 "DENYWRITE" prohibit write access by others
' 011 "DENYREAD" prohibit read access by others
' 100 "DENYNONE" allow full access by others. 111 network FCB (only available during server call)
' 7 inheritance. If set, file is private to current process and will not be inherited by child processes
Inregs.AX = &H3D00 + AL
CALL INTERRUPTX(&H21, Inregs, outregs)
IF outregs.FLAGS AND 1 THEN
PRINT "Error opening >> " + file$
' PRINT "The file was not found"
Inregs.AX = &H5900
Inregs.bx = Inregs.bx AND &HFF
CALL INTERRUPTX(&H21, Inregs, outregs)
PRINT "This is the error number:"; outregs.AX
BEEP: END
END IF
' Returns filehandle in AX
DIM filehandle AS INTEGER
filehandle = outregs.AX
PRINT "FileHandle:"; STR$(filehandle)