07.05.2015 Views

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

88 BRONZE <strong>Edition</strong> <strong>Guide</strong><br />

Reusing Stored Data For Input<br />

Each time you run the above program, it adds any missed questions to the end of the #2 file<br />

– your "output file". If you send output to the same file for several runs of the program, it<br />

may eventually contain a long list of questions.<br />

You could later use those saved questions to quiz yourself again because the questions and<br />

answers were printed to the file in a proper format for input. For example, assume you ran<br />

the program with TRIVDATA as the source of the questions and a file call REQUIZ for the<br />

missed questions. You could then run the program again, naming REQUIZ as the source<br />

of questions and a new file name to received the missed questions.<br />

Note: do not open the same file for both Channel #1 and #2! This is rarely, if ever, desirable,<br />

and with the TRIVIA program as written above, you'll get an error message if you attempt<br />

to do so. This is because <strong>True</strong> <strong>BASIC</strong> normally opens a file with "permission" to read from<br />

it and write to it, and one file can give only one "write permission" at a time.<br />

Reusing Stored Data For Input<br />

Look at the following questions, which you might want to add to a data file read by the<br />

TRIVIA2 program:<br />

Who wrote 20,000 Leagues Under the Sea, Jules Verne<br />

As written above, this line would produce the error message "Too many input items." <strong>True</strong><br />

<strong>BASIC</strong> would interpret the comma in 20,000 as marking the end of the first input item. You<br />

can place such an input string in double quotes to indicate that the comma is part of the<br />

string:<br />

"Who wrote 20,000 Leagues Under the Sea", Jules Verne<br />

But what if you want to place the title "20,000 Leagues Under the Sea" in quotes? You would<br />

have to use single quotes for the title, or you could repeat the double quotes where you want<br />

<strong>True</strong> <strong>BASIC</strong> to see them as quotes and not as markers for the end of the string:<br />

or<br />

"Who wrote '20,000 Leagues Under the Sea'", Jules Verne<br />

"Who wrote ""20,000 Leagues Under the Sea""", Jules Verne<br />

Although you can add quotes as necessary if you create the data file yourself, you could<br />

easily make mistakes. And it becomes even more complex if you want your program to<br />

PRINT such strings to a file for later use as input!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!