binder@asd.DEC.COM (NOW willya gimme some fightin' room?) (11/19/86)
Steven J. Dawson (SJDMK@UNO.BITNET) asks: > In a BASIC program, can you have two files open at once? One for reading > from and the other for writing to? I tried it but as soon as the program > came down to my input statement (which it was supposed to get from the input > file), I was prompted at the screen with a "?". Yes, you can have two files open at once. The BASIC command MAXFILES determines how many files you can have open - the number is set at 3 by default. The trick is that after you open a file you have to address it for READing or WRITEing (you knew that), and you have re-address each time you change files. The following quickie DOS 3.3-style program will demonstrate the process. Assume that INFILE is a sequential text file that exists. You want to copy it to OUTFILE, which is a new file. For the purposes of this example, assume also that its records are all 255 characters or less, and that it contains neither commas nor colons. 10 D$ = CHR$(4) 20 PRINT D$;"OPEN INFILE,S6,D1" : REM ** Set up your two files ** 30 PRINT D$;"OPEN OUTFILE,S6,D2" 40 REM 50 ONERR GOTO 200 : REM ** Set for EOF to kick out of transfer loop ** 80 REM 90 PRINT D$;"READ INFILE" : INPUT TEXT$ : REM ** Read one record. ** 100 REM 110 PRINT D$;"WRITE OUTFILE" : PRINT TEXT$ : REM ** Write the record. ** 120 REM 130 GOTO 90 : REM ** Loop until EOF knocks us out. *** 140 END 200 REM ** Error handler goes here, and includes a PRINT D$;"CLOSE" statement 210 REM together with the machine-language routine that the BASIC manual 220 REM gives for unwinding the stack after an error. This example differs from what you are doing by the fact that every disk access is preceded by either a READ or a WRITE command. If you don't do this, then BASIC stays set up for whatever type of disk access you last specified, and a data transfer of another type will address the console. Hope this helps. Cheers, Dick Binder (The Stainless Steel Rat) DEC Enet: ASD::BINDER UUCP: { decvax, allegra, ucbvax... }!decwrl!asd.dec.com!binder ARPA: binder%asd.DEC@decwrl.ARPA