Answer:

Yes.

File Name in a Variable

Nearly always a useful program asks the user for file names. For example, a word processor asks the user for the name of a file to edit (often called a document, but it is a file). Here is a QBasic program that asks the user for a file name, then writes the squares of the integers one through ten to that file:

' Write squares of integers to a file
'
CLS
INPUT "Enter file name:", NAME$   ' Ask user for a file name
OPEN NAME$ FOR OUTPUT AS #1       ' Open that file for output

PRINT #1, "Number", "Square"      ' Print column headings

FOR N = 1 TO 10                   ' For integers 1 through 10
  PRINT #1, N, N * N              ' Write the integer and its
NEXT N                            ' square to the file

END

The statement "Enter file name:", NAME$ asks the user to endter a file name. The name is read into the variable NAME$ as a string. Then the statement OPEN NAME$ FOR OUTPUT AS #1 Opens that file for writing and associates filen number #1 with it. The FOR loop writes ten lines to that file. Here is what the file looks like after the program finishes:

C:\QSOURCE>TYPE SQUARES.TXT
Number        Square
 1             1
 2             4
 3             9
 4             16
 5             25
 6             36
 7             49
 8             64
 9             81
 10            100

QUESTION 12:

Could this program be run a second time with a second file name?