QB help with disk files?

 BBS: Inland Empire Archive
Date: 04-12-92 (19:30)             Number: 98
From: LOGAN ASHBY                  Refer#: NONE
  To: DONALD SUTER                  Recvd: NO  
Subj: QB help with disk files?       Conf: (2) Quik_Bas
In a msg of <10 Apr 92>, Donald Suter writes to All:

 DS >       Help please, I have been trying to write a program to sort a
 DS > text file  of 1+ megs into smaller more manageable files.  The file is
 DS > to be sorted  into app. 34 files.  When I run the program it locks up

    For some reason, a lot of programming languages limit you to 15 file
handles, no matter what you have in your CONFIG.SYS file.
I don't think this is done by the languages but is a
problem with DOS. Here's a way to bump it up using CALL
Interrupt:

 - - - - - - - - - - - - - clip here - - - - - - - - - - - - - - - -
 ' Logan Ashby - 4/12/92 - public domain code

 '$INCLUDE: 'QB.BI'
 DIM RegsX AS RegTypeX
 CONST MaxFiles% = 40                    '| Max. # Files we want open
                                         '|   at one time.
 RegsX.ax = &H6700                       '| DOS Set # of File Handles Func.
 RegsX.bx = (MaxFiles% + 5) OR 1         '| Force # File Hnds to an odd #
 CALL InterruptX(&H21, RegsX, RegsX)
                                         '| Carry flag set, there was
 IF (RegsX.Flags AND 1) THEN             '|   an error
     PRINT "Error in Interrupt Call, DOS Error Code:"; RegsX.ax
     END
 END IF

 FOR i% = 1 TO MaxFiles%                 '| Now test it.
     PRINT "Opening File #"; i%
     FileName$ = "FILENUM." + LTRIM$(STR$(i%))
     OPEN FileName$ FOR OUTPUT AS #i%
     PRINT #i%, "This is FileNum "; i%
 NEXT i%
 CLOSE

 END

 - - - - - - - - - - - - - clip here - - - - - - - - - - - - - - - -

    This _should_ work with DOS versions 3.3 or later.  All the systems I
have access to have DOS 5.0 on them, so I couldn't test it
with earlier versions, but it did work on the ones I tried
it on.  You must have FILES in your CONFIG.SYS set at least
five greater than the number of handles you want for this
to work.  DOS claims five handles for its own use
internally.  The line in the code above where I force the
number of files handles requested to be an odd number is
because of a bug in DOS 3.3 that tries to allocate 64k for
the new file handle table when an even number of handles
are requested.

    One bit of weirdness.  The first time I tried to run
this in the IDE, it gave me DOS Error Code 8 - Not enough
memory.  I rebooted, tried it again, and it worked?!?  If
you can't get it to work within the IDE, try compiling it
and see if you have better luck running it from the command
line.  Remember to add the /L switch when you start QB for
any code that uses CALL Interrupt(X)

 DS >  I tried to post this once before, but I think it got lost, if this is
 DS > a  repeat please forgive me, and answer my question anyway.  Thanks.

    I saw it the first time but thought someone else would
probably be able to give a better answer, as I've never
needed to do this before.  Don't worry, you did the right
thing by hollering until somebody answered. <grin>  Hope
this works for you.  If you have any questions about the
code, fire off a message, and I'll try to answer them.

seeya,
Logan

--- GoldED 2.31p
 * Origin: Lurker's Lounging Point (1:398/1.2)
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