BBS: Inland Empire Archive Date: 07-08-92 (22:44) Number: 272 From: MATT HART Refer#: NONE To: BILL CAMPBELL Recvd: NO Subj: Error handling Conf: (2) Quik_Bas
BC> handling and recompiled (using /e and /x) and found that those 8
BC> lines of code cost me about an extra 10k. All I want to do is
BC> trap for a file not being there when I try to open it.
All you need is /X - /E is for trapping without resume, /X
handles with or without. You should make a seperate .BAS
program, and link with it. Here's also a way to do it with
an interrupt call:
'
' EXIST.BAS by Matt Hart
' Uses Interrupt 21H to see if a file exists.
'
DEFINT A-Z
TYPE RegTypeX
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
ds AS INTEGER
es AS INTEGER
END TYPE
DECLARE FUNCTION Exist(File$)
File$="EXIST.BAS"
File$=command$
Print Exist(File$)
END
FUNCTION Exist(File$)
DIM InRegs as RegTypeX
DIM OutRegs as RegTypeX
DIM DTA as string * 42
DIM F as string * 64
InRegs.AX = &H1A00
InRegs.DS = VARSEG(DTA)
InRegs.DX = VARPTR(DTA)
CALL InterruptX (&H21, InRegs, OutRegs)
F = File$+CHR$(0)
InRegs.AX = &H4E00
InRegs.CX = 0
InRegs.DS = VARSEG(F)
InRegs.DX = VARPTR(F)
CALL InterruptX (&H21, InRegs, OutRegs)
if OutRegs.AX = 2 or OutRegs.AX = 18 then
Exist = 0
else
Exist = -1
endif
END FUNCTION
Without an interrupt call (and typed without testing!):
ON ERROR GOTO ErrorTrap
FUNCTION Exist(File$)
SHARED Ecode
Ecode = -1 ' Assume it exists
Fil = FREEFILE
OPEN File$ FOR INPUT AS Fil
CLOSE Fil ' code goes here if file exists AND
Exist = Ecode ' after the errortrap
ON ERROR GOTO 0 ' trapping OFF
END FUNCTION
ErrorTrap:
Ecode = 0 ' code goes here after the OPEN if it doesn't exist
RESUME NEXT ' continue at the close
~~
---
* Origin: Midnight Micro! V.32/REL (918)451-3306 (1:170/600)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET