Hi Raven Vegeta
Thanks for the help The lottery code is:
Arrays are going to be a very important part of your
future programs. They allow you to store large
amounts of data under a single name. You can then
access the data by index rather than by name alone.
If you had to write a program that stored each
weeks lottery numbers, typing out 52 unique
variable names is a lot of work, hard to maintain
and quite unnecessary. Arrays allow you to create a
special kind of variable that can store more than
one item of data. You might start your program like
this:
lottery1$="43,76,12,34,12,11"
lottery2$="76,12,34,12,11,44"
lottery3$="12,34,12,02,05,07"
etc..
Two hours later, you realize you could have written
it like this:
DIM lottery$(52)
lottery$(1)="43,76,12,34,12,11"
lottery$(2)="76,12,34,12,11,44"
lottery$(3)="12,34,12,02,05,07"
etc..
We declare a string array using the DIM command
followed by a name for our array. Like variables,
when we use a dollar symbol after the name we
instruct the program to use the array to store only
strings. We then enclose in brackets how many
items of data we wish the array to store. The array
can be filled almost like a variable, but you must
also provide the position within the array you wish
to store your data.
But you then ask yourself what benefits I would
have gained using the second approach. If you
where also required to print out all 52 lottery
numbers to the screen with your first approach you
would have to add another 52 statements that
printed each variable:
PRINT lottery1$
PRINT lottery2$
PRINT lottery3$
etc..
But if you had used an array, the same example
would look like this:
PRINT lottery$(1)
PRINT lottery$(2)
PRINT lottery$(3)
etc..
You will have noticed that by using an array, you no
longer have to refer to your data using a unique
variable name. You can now point to the data you
want using a position number. Accessing data this
way has a thousand advantages over trying to
access data by variable name alone, as you will
discover. One example would be to improve the
above like this:
FOR T=1 TO 52
PRINT lottery$(T)
NEXT T
Incredibly the above code replaced 52 PRINT
statements with just 3 statements. With the above
example, T is incremented from 1 to 52 within a
loop that prints out the contents of the array at that
position.
Arrays can also store multiple levels of data. At the
moment our lottery entries are stored as strings and
the numbers are hard to get at. Let's say we wanted
to store all six numbers for every lottery week, we
would create an array like this:
DIM lottery(52,6)
Without the dollar symbol($), we are declaring the
array to store integer numbers instead of strings.
You will also notice we have a second number
separated by a comma. This means for every array
position from 1 to 52, there is a sub-set numbered
1 to 6 in which multiple data can be stored. You can
visualize an array as a filing cabinet with large
draws numbered 1 to 52. Within each of the 52
draws is a tray with 6 boxes inside. You can store a
value in each box. In all you can store 312 (52 x 6)
values in this array. You can have up to five
dimensions in your array, which means you can
create an array as big as (1,2,3,4,5). Be careful
when declaring dimensions, as large arrays
consume large amounts of memory and may reduce
overall performance of your program.
Entering data into our new array is elementary:
lottery(1,1)=43
lottery(1,2)=76
lottery(1,3)=12
lottery(1,4)=34
lottery(1,5)=12
lottery(1,6)=11
lottery(2,1)=43
lottery(2,2)=76
lottery(2,3)=12
lottery(2,4)=34
lottery(2,5)=12
lottery(2,6)=11
You are now able to give your program access to
much more useful data. Unlike the string approach,
you could make your program count how many
times a certain number has appeared.
As you have determined, arrays need to be declared
as a particular type. You can have an array of
integer numbers, real numbers or strings. You
cannot have multiple types in the same array, but
you can declare new arrays dedicated to holding
such data.
As I am a total novice I couldn't make much of this out.
Cheers
Here's looking at you, kid