Opens a file for a specific direction in a specified device.
OPEN "<devicename>[\<path>][\][<filename>]" [FOR <direction>] AS [#]<number> [LEN=<length>]
Note: Character backslash (\) is used in Disk BASIC 2.x. It is replaced by the character yen (¥) on Japanese MSX.
<devicename> specifies the used device. Here are the useful devices for OPEN and the different types of access for these devices:
|Device type||Device name||Remark||Sequential||Random|
|followed by :||OUTPUT||INPUT||APPEND|
|Disk drive||A:, B:, C:, D:, E:, F:, G:, H:||X||X||X||X|
|Data recorder||CAS:||Not available on MSX Turbo R||X||X||-||-|
|Serial device||COM:||Requires RS-232C interface||X||X||-||-|
|Text screen||CRT:||Filename and direction not required||X||-||-||-|
|Graphic screen||GRP:||Filename and direction not required||X||-||-||-|
|High Graphic screen (*)||HIGRP: (**)||Filename and direction not required||X||-||-||-|
|Printer||LPT:||Filename and direction not required||X||-||-||-|
|Memory disk||MEM:||Created with CALL MEMINI||X||X||X||-|
|Quick Disk drive||QD[n]:||n=0 by default ; can vary between 0 and 7||X||X||-||-|
|not followed by :|
|Console||CON||Filename and direction not required||X||X||X||X|
|Printer||LST||Filename and direction not required||X||X||X||X|
|Bit heaven||NUL||Filename and direction not required||X||X||X||X|
|Printer||PRN||Filename and direction not required||X||X||X||X|
(*) only on screen 6, after installation of HI-GRAPhics, written by Arjen Schrijvers (see Interlacing Demo)
(**) it must be OPEN "HIGRP:NTSC" or OPEN "HIGRP:PAL"
<path> is used to specify the location in folders of file to load. Each folder name in path are separate by a backslash (\). This parameter is only available in version 2 of Disk BASIC.
<filename> is the name of the file to be opened. This parameter is not required for text screen, graphic screen and printer.
The format of file name is limited to 6 characters without extension, when using cassette. If another device is used, then the format is 8 characters followed by a point and an extension with 3 characters.
<direction> is one of the 3 types of sequential access:
OUTPUT = sequential write
INPUT = sequential read
APPEND = sequential write to the end of an existing file
This parameter is not required for text screen, graphic screen and printer, but the listing is more easy to read when you use it. To open a file with random access on disk, you need to skip the [FOR <direction>] parameter.
<number> is a number that you must assign to open the file. It can vary between 1 and 15, but can't exceed the maximum number of files eventually defined with MAXFILES.
<length> is an optional parameter to use only if you choose to open a file in random access on disk. You can specify the length of this file. It must be an integer. The default value is 256.
10 SCREEN 2:COLOR 15,4,7 20 OPEN "GRP:" FOR OUTPUT AS #1 30 LINE (32,32)-(120,120),6,B 40 CIRCLE (120,120),56,1 50 PRESET (40,8) 60 PRINT #1,"Text in graphic screen" 70 FOR I=1 TO 2000: NEXT I 80 END
5 'Open a random file on disk with 512 as length 10 OPEN "A:RECORD.DAT" AS #1 LEN 512
10 ' Create a text file 20 OPEN"hello!.txt" FOR OUTPUT AS #1 30 PRINT#1,"Hello world!"+CHR$(10)+CHR$(13)+"I'm the saved text from" 40 PRINT#1,"the file HELLO!.TXT" 50 CLOSE 60 ' Print a text file 70 OPEN"hello!.txt" FOR INPUT AS #1 80 INPUT#1,A$:PRINT A$ 90 IF NOT EOF(1) THEN 80 100 CLOSE
MSX-BASIC 1.0 or higher