Error checking in QB

 BBS: Inland Empire Archive
Date: 10-11-92 (14:55)             Number: 323
From: JOHN GALLAS                  Refer#: NONE
  To: VICTOR YIU                    Recvd: NO  
Subj: Error checking in QB           Conf: (2) Quik_Bas
VY>I have been having to writing a "shell" for each thing... like a function
VY>called OpenFile that returns success/failure and error checking occurs
VY>in there...

How about if in OpenFile it checks if the file exists or not before it
opens it?  Heres a function that'll check for the existance of a file:

DECLARE FUNCTION FileExists% (FileName$)
'In order to use the above function, you must have started QuickBASIC
'from the command line using the /L switch. e.g. "QB /L"
'Now include the following lines in the main body of your code:
DIM SHARED Register AS RegTypeX
'You may now use this routine to test for the existence of any file
'as follows:
IF FileExists(File$) THEN
  PRINT "yes, "; File$; " does exist"
  PRINT "no, "; File$; " does not exist"
'The function returns True (-1) if the file exists and False (0) if
'it does not exist.
'To test for the existence of any directory, you may use the same
'function and take advantage of the fact that the NUL device is treated
'by DOS as a file that exists in every directory. Thus:
Dir$ = "C:\DOS"
IF FileExists(Dir$ + "\NUL") THEN
  PRINT "yes, the directory "; Dir$; " does exist"
  PRINT "no, the directory "; Dir$; " does not exist"

FUNCTION FileExists% (FileName$) STATIC
' *** set new DTA
DTA$ = SPACE$(128) = &H1A00
Register.ds = VARSEG(DTA$)
Register.dx = SADD(DTA$)
CALL INTERRUPTX(&H21, Register, Register)
' *** get first matching file = &H4E00 = &H6
TempFileName$ = FileName$ + CHR$(0)
Register.ds = VARSEG(TempFileName$)
Register.dx = SADD(TempFileName$)
CALL INTERRUPTX(&H21, Register, Register)
FileExists% = ((Register.flags AND 1) = 0)
DTA$ = "": TempFileName$ = ""

There ya go!

 * OLX 2.1 TD * Computer Programmer Wanted; Some assembly required.
--- RyPacker v2.5
 * Origin: The Ghost Mode - An RyBBS System!  (612)-688-0026 (1:282/3006)
Outer Court
Echo Basic Postings

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