TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: BRIAN MCLAUGHLIN
date: 1995-10-21 18:33:00
subject: OPEN MORE THAN 15 FILES

Over the years I must have seen a couple dozen messages posted that
went like this:
"...I changed my CONFIG.SYS to read FILES=100, but BASIC will only
let me open 15 files. What's wrong?..."
Here is some PowerBASIC 3.x code to let your program open more than
15 files at once, and all the information you need to understand and
use that code.
First off, it isn't BASIC that is limiting your program to 15 open
files at once.  It's DOS.  Even though DOS lets you put a FILES=255
statement in your CONFIG.SYS, DOS still rations out its file handles
like a miser giving away dollar bills.
When you boot up DOS, one of the first things it does is open 5 file
handles for its own use, and assign them to a set of five standard
devices, like the screen and the keyboard.  Then, when your program
starts, DOS lets it use those 5, plus 15 more handles for its own
files, for a total of 20.
So what good is the FILES=255, if your program only gets 20?
It goes like this.  Your program can get more than 20, as long as it
asks for them, nicely.  There's a DOS service, &H67, that sets the
maximum number of file handles your program can use.  Unless you
call &H67, you get no extra handles. Understand?
BUT, you have to send it the number of open files you want, plus 5.
Yes, that's right.  Say, you want to be able to open 30 files at
once, not 15.  Then you must send a value of 35.  The extra five are
the five DOS devices! DOS counts them against your limit.
The other catch is that, if you send it a number larger than the
FILES=XXX setting in your CONFIG.SYS, the XXX will act as a ceiling.
You shouldn't be able to get more than XXX file handles, minus the
five handles for DOS.
Here's the code:
'------------------------- START CODE ----------------------------
DECLARE SUB ExpandHandles (BYVAL TotalHandleCount%, ErrValue%)
'==============================================================
 SUB ExpandHandles (BYVAL TotalHandleCount%, ErrValue%)  PUBLIC
'==============================================================
' Using this SUB, you can change the number of file handles
' your program can open, up to the highest number allowed under the
'
'    FILES=XXX
'
' statement in the CONFIG.SYS file, provided the program is running
' under DOS v3.3 or higher.
'
' The number you pass to this SUB should be the total number of files
' you want to be able to open, plus 5 (to allow for DOS stdxxx handles).
'
' If you pass a number higher than the XXX in FILES=XXX, there will
' NOT be an error reported in ErrValue%...I don't know why DOS doesn't
' flag that as an error. It just doesn't!
  ErrValue% = 0                       ' assume no error
  IF TotalHandleCount% > 20 THEN      ' hey! we get 20 automatically!
    MemToFree% = (TotalHandleCount% - 20) * 2
    MEMPACK                           'pack memory first
    dummy& = SETMEM(-MemToFree%)      'free the memory next
    ASM    Mov  AH, &H67              ; DOS function 67h in AH
    ASM    Mov  BX, TotalHandleCount% ; puts new handle total in BX
    ASM    Int  &H21                  ; call DOS interrupt
    ASM    Jnc  NoError               ; if carry flag set, we failed
    ASM    Mov  ErrValue%, AX         ; otherwise, return the error
  END IF
NoError:
END SUB
'---------------------------- END CODE -----------------------------
 * SLMR 2.1a * MAXLIB For PB v1.2 - Access arrays and files in EMS/XMS!
--- WILDMAIL!/WC v4.12 
---------------
* Origin: NWCS Online (1:105/362.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.