An array gives you some special variables.
When you've mastered the use of arrays, they will be a help to you.
Any time you use an array, you have to use the DIM keyword first.
If you put...
DIM Q$(2),A$(2)
... in a program, that gives you six variables you can then use...
Q$(0) Q$(1) Q$(2) A$(0) A$(1) A$(2)
As usual, the $ at the "end" (well, the end before the bit in ()'s!) of the variable name means that this variable will be able to hold any character.
I've used arrays in the following geography test/ exercise....
REM bas6zero-test-by-array.bbc REM vers 25 Feb 25 REM started 25 Feb 25 Q$(0)="France" A$(0)="Paris" Q$(1)="Italy" A$(1)="Rome" Q$(2)="India" A$(2)="Delhi" 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
Much of that is unremarkable... but did you see the
A$(WhichQ%)
??? (It appears twice)
WhichQ% is an ordinary variable.
If WhichQ% holds, say, 1 in it when IF Ans$=A$(WhichQ%)... is executed, then, at that time, A$(WhichQ%) is as good as A$(1)
This is another of those things which is very cool... but which it may take you a while to see as very cool.
That's enough for now... we'll meet arrays again later. The next tutorial concentrating on how arrays can help you is bas6-introduction-to-arrays.htm.
Please get in touch if you discover flaws in this page. Please mention the page's URL. (wywtk.com/prgm/bas/bas6zero-first-steps-arrays.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.
|
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.
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org.
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 .....