Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arrays in BASIC

21 views
Skip to first unread message

Paul Stewart

unread,
Jan 2, 2022, 3:36:08 PM1/2/22
to
Hi guys,

Need to pick you brains on Arrays.

Looking at Arrays in the Archimedies User Guide (vintage July 1987), I
have come to the understanding that it is possible to declare an array
local to a function or procedure. Having tried to do this, I keep getting
Syntax Error.

I am trying using: LOCAL DIM a$(1,1)

Also tried different permutations, but all come back with Syntax error.

Am I barking up the wrong tree here or just completely misunderstanding
the examples provided?

Any advice examples you can give, much appreciated.


--
Paul Stewart
Sent from A9home running RISC OS 4.42

Harriet Bazley

unread,
Jan 2, 2022, 4:01:54 PM1/2/22
to
On 2 Jan 2022 as I do recall,
>L.
10 PROCarray
16 PRINT D$(1)
17 END


20 DEF PROCarray
30 LOCAL D$()
40 DIM D$(7)
50 D$(1)="hat"
55 PRINT "array", D$(1)
60 ENDPROC

>RUN
array hat
Undimensioned array at line 16

--
Harriet Bazley == Loyaulte me lie ==

Nothing is foolproof - to a sufficiently talented fool

Paul Stewart

unread,
Jan 2, 2022, 4:56:40 PM1/2/22
to
In message <65baa8a45...@bazleyfamily.co.uk>
Harriet Bazley <har...@bazleyfamily.co.uk> wrote:

>>L.
> 10 PROCarray
> 16 PRINT D$(1)
> 17 END


> 20 DEF PROCarray
> 30 LOCAL D$()
> 40 DIM D$(7)
> 50 D$(1)="hat"
> 55 PRINT "array", D$(1)
> 60 ENDPROC

>>RUN
> array hat
> Undimensioned array at line 16

Thanks for this. Your code works perfectly.
Calling your PROCarray procedure twice, again works as expected.

Trying the same in my code, "Arrays cannot be redimensioned" error.

"Argh"

Something in my code not not right, so will take another look.

Thanks very much for your response.

Martin

unread,
Jan 2, 2022, 5:05:48 PM1/2/22
to
In article <65baa8a45...@bazleyfamily.co.uk>,
Harriet Bazley <har...@bazleyfamily.co.uk> wrote:
> On 2 Jan 2022 as I do recall,
> Paul Stewart wrote:

> > Need to pick you brains on Arrays.

> > Looking at Arrays in the Archimedies User Guide (vintage July
> > 1987),

[Snip solution from Harriet]

But that manual is 35 years old (gosh!)

You should download the BASIC manual from
https://www.riscosopen.org/content/downloads/common
which is *much* more up to date!

--
Martin Avison
Note that unfortunately this email address will become invalid
without notice if (when) any spam is received.

Paul Stewart

unread,
Jan 2, 2022, 5:18:35 PM1/2/22
to
In message <12c0ada...@outlook.com>
Turns out, there were two arrays in the same procedure.
Having fixed the first one by making it local, just got fixated on that
array. Having looked at the line number again that the error was being
reported against, it was actually the second array it was complaing about.

Now moved dimensioning of second array out of the procedure, and all is
working as expected.

Again, thanks for your assistance with dimensioning a local array.

Harriet Bazley

unread,
Jan 2, 2022, 5:53:25 PM1/2/22
to
On 2 Jan 2022 as I do recall,
Martin wrote:

> You should download the BASIC manual from
> https://www.riscosopen.org/content/downloads/common
> which is *much* more up to date!
>
There's certainly stuff in there about arrays that I had no idea about -
I don't know if that's because it's genuinely new since 1987, or because
I never attempted whole-array operations....


10 DIM A(2,2)

60 A() += n%*n%

equates to "square the variable n% and increase each and every element
in the array A() by the result of that calculation"

--
Harriet Bazley == Loyaulte me lie ==

But I don't like Spam!!!!

Martin

unread,
Jan 2, 2022, 6:19:26 PM1/2/22
to
In article <d014b2a45...@bazleyfamily.co.uk>,
Harriet Bazley <har...@bazleyfamily.co.uk> wrote:
> On 2 Jan 2022 as I do recall,
> Martin wrote:

> > You should download the BASIC manual from
> > https://www.riscosopen.org/content/downloads/common
> > which is *much* more up to date!

> There's certainly stuff in there about arrays that I had no idea
> about - I don't know if that's because it's genuinely new since
> 1987, or because I never attempted whole-array operations....

> 10 DIM A(2,2)
> 60 A() += n%*n%

> equates to "square the variable n% and increase each and every
> element in the array A() by the result of that calculation"

I should perhaps have pointed out that the manual I referred to
includes updates for recent versions of BASIC (see section on
changes) and I have noticed that Paul is running RO4.42 ... so may
not have a recent version, though it can be run in ancient versions
of RISC OS.

Steve Drain

unread,
Jan 3, 2022, 4:47:53 AM1/3/22
to
On 02/01/2022 22:43, Harriet Bazley wrote:
> On 2 Jan 2022 as I do recall,
> Martin wrote:
>
>> You should download the BASIC manual from
>> https://www.riscosopen.org/content/downloads/common
>> which is *much* more up to date!
>>
> There's certainly stuff in there about arrays that I had no idea about -
> I don't know if that's because it's genuinely new since 1987, or because
> I never attempted whole-array operations....

Whole array operations have been there from the first BASIC V. I am
particularly fond of array multiplication, the . operator. This makes
vector transformations a doddle. It is a pity there are not more matrix
operations.


> 10 DIM A(2,2)
>
> 60 A() += n%*n%
>
> equates to "square the variable n% and increase each and every element
> in the array A() by the result of that calculation"

Just a warning that the apparently similar:

60 A() = n%*n%

has to be:

60 A() = (n%*n%)

And do not forget:

A() = 1,2,3,4,5,6

to fill an array.
0 new messages