Page 1 of 1

Assign values to an array.

Posted: Tue Jan 29, 2019 2:33 am
by Ken
Hi
If I have a dimensioned array, say Dim x(3), how can I assign a value to each part. Say 20, 30, 40
Thanks

Re: Assign values to an array.

Posted: Tue Jan 29, 2019 3:21 am
by rbytes
If I have a dimensioned array, say Dim x(3), how can I assign a value to each part. Say 20, 30, 40
You can do it with individual value assignments:

X(1)=20
X(2)=30
X(3)=40

Or use a loop to assign the values:

FOR t=2 TO 4
X(t-1)=t*10
NEXT t

The loop is probably overkill for this small number of value assignments, but becomes more and more efficient as the number increases.

No need to DIM x unless you need it dimensioned larger than 10. And case doesn't matter in a variable, so X is the same as x.

Re: Assign values to an array.

Posted: Tue Jan 29, 2019 3:41 am
by Ken
Hi
Thanks for that.
What if I have a mixed up set of values say to make a polygon. X is 23, 56, 67 y is 43, 59, 120 etc. I am guessing I would use data and read. Is that the best way?
Ken

Re: Assign values to an array.

Posted: Tue Jan 29, 2019 4:16 am
by rbytes
Yes, that works very well. Use a loop to read the x and y values from DATA statements into two arrays named x and y

Then use the poly command to draw the shape. Notice that where X and Y appear in the poly command, arrays are expected. The parameters shown in square brackets are optional.

DRAW POLY X,Y [COUNT N START S]

Give it a try and if you need an example afterward I can post one.