[NTLK] NSBasic Question - arrays
M. Horvat
redjazz_slo at yahoo.com
Tue Aug 24 11:05:21 EDT 2010
> > Can NSBasic handle arrays of more than a
> single dimension? I see the
> > definition that shows dim a[10] but I have tried dim
> a[b,c] and it does
> > not work. I cannot find an example of 2 or 3
> dimensional arrays.
First of all, your code begins with
0010 dim a[b,c]
where 'b' and 'c' are undefined (ie. they have no value).
However, you can simulate two-dimensional arrays like this:
0008 let Columns=5
0009 let Rows=4
0010 dim a[Rows*Columns]
0020 for y=1 to Rows
0030 for x=1 to Columns
0040 read a[(y-1)*Columns+x]
0050 next x
0060 next y
0070 data 0,2,3,0
0080 data 1,0,5,0
0090 data 0,4,0,1
0100 data 3,5,0,0
0110 data 4,0,0,2
(Note: this wasn't tested.)
If it doesn't work, add '-1' to line 40, before ']'. I can't remember whether NS Basic starts counting at 0 or 1. It probably doesn't let you explicitly specify the starting and ending subscripts of arrays.
(And do yourself a favor and use descriptive variable names, even though they take more time to type. They'll make things much easier.)
-Matej Horvat
More information about the NewtonTalk
mailing list