Re: existing file check

 BBS: Inland Empire Archive
Date: 11-18-92 (11:18)             Number: 378
From: DIK COATES                   Refer#: NONE
  To: BOB SEWELL                    Recvd: NO  
Subj: Re: existing file check        Conf: (2) Quik_Bas
 >>>> QUOTING Bob Sewell to Jim Coyle <<<<

Generally try to avoid ON ERROR calls and take care of error
handling outside of BASIC because it brings in a whole bunch
of additional code, and bloats file sizes...some of the programs
I have written are over 1 meg in size and memory is really a
scarey thing!

Have posted one also using BASIC Functions...My actual method for
checking for file uses the same approach you have mentioned, only
in Assembly, as part of one of my own libraries. Also use NOT and
return -1.  Should have mentioned it, because blending ASM with
BASIC has some real benefits.  I have massaged the code that you
have loaded and have included it below.  Have modified the 4th
line of code to use SSEG function.  If the program is done in
Assembly, the executable code size is the smallest of all...
Using the DIR$ function (if available to compiler) gives the smallest
executable size, save actual ASM function, and doesn't require
loading the qbx library.

Using DIR$:
**********

FUNCTION FILEEXIST1% (FileName$)

  IF LEN(DIR$(FileName$)) THEN
    FILEEXIST1% = -1
  END IF

END FUNCTION



Using InterruptX:
****************

FUNCTION FILEEXIST2% (FileName$)

  temp$ = FileName$ + CHR$(0)

  InRegX.AX = &H4E00                                'find first matching file
  InRegX.DX = SADD(temp$)                                'offset of FileName$
  InRegX.DS = SSEG(temp$)                             'segment of FileName$
  InRegX.CX = 0                                         'normal file, no dirs
  CALL InterruptX(&H21, InRegX, OutRegX)


  IF (OutRegX.FLAGS AND 1) = 0 THEN               'check if carry flag is set
    FILEEXIST2% = -1
  ELSE
    FILEEXIST2% = 0
  END IF

END FUNCTION



Executable file sizes for both approaches without using a CALL are as
follows:

using FILEEXIST1% and no function calls, gives EXE file size = 23140 bytes
using FILEEXIST2% and no function calls, gives EXE file size = 32837 bytes


Dik

... Stop!!! Don't touch that damn phon+dyT-+Dikuo/oon,H+
___ Blue Wave/QWK v2.10

--- Maximus 2.00
 * Origin: Durham Systems (ONLINE!) (1:229/110)
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