Only one file can be associated with one file number.
It is perfectly fine to open more than one file. Here is the corrected version of the program:
CLS ' Clear screen OPEN "MYFILE.TXT" FOR OUTPUT AS #1 ' Open the file for output OPEN "URFILE.TXT" FOR OUTPUT AS #9 ' Open the file for output PRINT #1, "Hello World" ' Send characters to the first file PRINT #9, "Hello Mars" ' Send characters to the second file END ' End the program
The file numbers are arbitrary (you don't have to number files #1, #2, #3 ... in sequence).
This program will write out the first string to the first file and the second string to the second file. You could continue writing strings to the two files in any order.
Here (again) is a description of the OPEN
statement:
OPEN file$ FOR mode AS filenumber
file$
is the name of the file.mode
isINPUT
orOUTPUT
.filenumber
is a number 1 through 255. Use a separate number for each file.
Could the file name be contained in a string variable?