| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (divide) (equal) (less) (minus) (more) (multiply) (plus) (power) Abs And Append Asc Atn Auto Backup Bank Begin Bend Bload Boot Box Bsave Bump Catalog Char Chr Circle Close Clr Cmd Collect Collision Color Concat Cont Copy Cos Data Dclear Dclose Dec Def Delete Dim Directory Dispose Dload Do Dopen Draw Ds Ds string Dsave Dverify El Else End Envelope Er Err Exit Exp Fast Fetch Filter Fn For Fre Get Get num Getkey Go Gosub Goto Graphic Gshape Header Help Hex If Input Input num Instr Int Joy Key Left Len Let List Load Locate Log Loop Mid Monitor Movspr New Next Not Off On Open Or Paint Peek Pen Pi Play Pointer Poke Pos Pot Print num Pudef Quit Rclr Rdot Read Record Rem Rename Renumber Restore Resume Return Rgr Right Rlum Rnd Rreg Rspcolor Rsppos Rsprite Run Rwindow Save Scale Scnclr Scratch Sgn Sin Sleep Slow Sound Spc Sprcolor Sprdef Sprite Sprsav Sqr Sshape St Stash Step Stop Str Swap Sys Tab Tan Tempo Then Ti Ti string To Trap Troff Tron Until Using Usr Val Verify Vol Wait While Width Window Xor Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
DCLOSE [ # fileNumver ] [ , D driveNumber ] [ { , | ON } U unitNumber ] ... [ , ItwoChar ] [ , R ] ...
Close a specific file, or "safe" close all files on a specific device.
DCLOSE without a fileNumber closes all files open on the device given (or implied) by unitNumber. This is similar to DCLEAR but no "initialize" command is sent to the device. It is also similar to CLR, but more specific (only affects one device), and more imporatantly DCLOSE really closes the files (CLR just "forgets" them which can result in corrupted data if any files were open for writing). With a fileNumber, BASIC will close that specific file. If the file is not open, there will be no error (assuming the Syntax is valid). Assuming the file was open and has been closed, there is a (potential) bug: the secret variable "DosFA" is not set to the device corresponding to the file. This is appropriate if the file is not a "disk device" (don't know why you would use DCLOSE in that case!). Assuming the file was for a "disk" device, then the secret "DosFA" may be set to the wrong value (it is set to 8 unless you give a specific unitNumber). When you close a file for writing, it is usually a good idea to check the device status with DS or DS$ to be sure it was closed appropriately. However because of the bug just described, this may report on the wrong device. A good example would be a system with two "disk" devices, unit 8 and unit 9 (both turned on with and working normally). If you write a file to unit 9, then DCLOSE it without specifiying unitNumber 9, then when you try to check for errors with DS or DS$, you will get an "OK" message from unit 8. This would allow an error with your file (on unit 9) to go unnoticed. Worse, if device 8 is not powered on, you would get a DEVICE NOT PRESENT ERROR when trying to test DS or DS$. You can avoid the bug if you always give the correct unitNumber corresponding to the file you are closing. This means you have to be responsible for remembering which fileNumber is using which unitNumber. Simple task in a simple program (using constant values), more work and potential for error in more complex programs. Really sad because the system has the information already, but BASIC just throws it away. If an expression (enclosed in parentheses) is not valid, or an expression is used without parentheses, SYNTAX ERROR occurs. If any parameter is not the correct type a TYPE MISMATCH ERROR will be generated. Otherwise if a parameter is not a legal value (see table above), an ILLEGAL QUANTITY ERROR is generated. Like all disk commands and statements, the Syntax is more flexible than shown above. In particular, the parameters may be given in any order. The general restrictions are: a comma (,) must not precede the first parameter (ON may do so), any non-literal value (a variable name or expression) must be enclosed in parentheses (), and do not supply the same parameter more than once. Exceptions include the U and R parameters, which may used an unlimited number of times (R is ignored and the last unitNumber is used), and the twoChar parameter which must always be two literal characters (it may not be repeated although it is otherwise ignored). If the specified fileNumber was open for writing, you may want to check the error/status channel with DS or DS$ to ensure it was properly closed by the device. This generally only fails if the disk is full. Like all disk-based commands, DCLOSE restricts the driveNumber to either 0 or 1, but it doesn't matter because the driveNumber is not used by BASIC. Like all disk-based commands, DCLOSE will reset DS$ and set the secret variable "DosFA" to the unitNumber (defaults to 8 if not given), even if the fileNumber was opened on a different device! If any files were actually closed, it also indirectly updates ST. Examples:
|