index-bas.htm wywtk.com homepage What You Want To Know  Index to my pages about BBC BASIC

How to use the DATA keyword in BBC BASIC for SDL

(Page's URL: bas7-data-keyword.htm)

This tutorial extends the program we did when taking our first steps with arrays. You probably won't need to go back to that. But visit it if you have any difficulty with what is in the tutorial you are reading now.

The only new material which this tutorial adds is the use of DATA and READ to fill the Q$() and A$() arrays. (The exercise's questions and their answers

The lines starting with the keyword DATA are "hidden" from users of the program.

They are there to supply data to any READs in the code.

If you said READ A$, the program would take a word or phrase from a DATA statement.

The first READ takes the first word or phrase from the first DATA. The next takes the next, and so on.

READ and DATA can also be used to fill numeric variables...

DATA 23,6
DATA 100

READ A%, B%, C%

PRINT A%
PRINT B%
PRINT C%+34

... would print 23, 6 and 134.

The following shows you (I hope!) why I said that READ can pick up a word or a phrase...

DATA apple, mandarin orange, pear

READ A$, B$, C$

PRINT A$
PRINT B$
PRINT C$

... would print...

apple
mandarin orange
pear

For example...

The program below shows you READ and DATA in action.

REM bas7-data keyword.bbc
REM vers 25 Feb 25
REM started  25 Feb 25

DIM Q$(5),A$(5)

DATA France,Paris,Italy,Rome,India,Delhi
DATA China,Beijing,Peru,Lima

Index%=0
REPEAT
     READ Q$(Index%),A$(Index%)
     Index%=Index%+1;
     A$(0)="Paris"
UNTIL Index%=5

PRINT "Enter 000 at any time to finish"

REPEAT
     WhichQ%=RND(3)-1
     PRINT "What is the capital of ";Q$(WhichQ%)
     INPUT Ans$

     IF Ans$="000" THEN
        PRINT "Goodbye"
        WAIT (90)
        QUIT
     ENDIF

     IF Ans$=A$(WhichQ%) THEN PRINT "Right"
     IF Ans$<>A$(WhichQ%) THEN PRINT "Not right"

     PRINT

UNTIL FALSE

REM CHALLENGE: Add scoring, and a report of score at end.
REM CHALLENGE: Get program to provide right answer when user does not
REM CHALLENGE: Add code to let user have a second attempt
REM CHALLENGE: Make the user type the RIGHT answer if he/she had to be told


Going Further...

I'm not explaining these two sentences at this time. See if you can figure out what they mean! (The come from the excellent BBC BASIC Manaual by R.T. Russell.)

RESTORE can be used at any time in a program to set the line where DATA is read from.
RESTORE on its own resets the data pointer to the first data item in the program.

You can use DATA and RESTORE perfectly well without using restore... but if you learn how to use RESTORE, more things become possible!


A few words from the sponsors...

Please get in touch if you discover flaws in this page. Please mention the page's URL. (wywtk.com/prgm/bas/bas7-data-keyword.htm).

If you found this of interest, please mention in forums, give it a Facebook "like", Google "Plus", or whatever. If you want more of this stuff, help!? There's not much point in me writing these things, if no one feels they are of any use.



index sitemap
What's New at the Site Advanced search
Search tool (free) provided by FreeFind... whom I've used since 2002. Happy with it, obviously!

Unlike the clever Google search engine, this one merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have four other sites, and that this search will not include them. They have their own search buttons.

My SheepdogSoftware.co.uk site, where you'll find my main homepage. It has links for other areas, such as education, programming, investing.

My SheepdogGuides.com site.

My SkyWoof.com site.

My site at Arunet.




How to email or write this page's editor, Tom Boyd. Please cite page's URL if you write.


Valid HTML? Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org.

AND tested for... Valid CSS?



(eXTReMe tracker icon) Why is there a script or hidden graphic on this page? I have my web-traffic monitored for me by eXTReMe tracker. They offer a free tracker. If you want to try one, check out their site. Neither my webpages nor my programs incorporate spyware, but if the page has Google ads, they also involve scripts. Why do I mention the script? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....