Page 1 of 1
Trouble with 2-dimensional array
Posted: Sat Jan 14, 2017 8:46 pm
by sarossell
This simple example is supposed to populate the array " j " and then print the contents (1 thru 9), but it fails unexpectedly. Any suggestions would be greatly appreciated.
Code: Select all
arrays:
OPTION BASE 1
c=0
DIM j(3,3)
FOR n=1 TO 3
FOR m=1 TO 3
PRINT n,m
c=c+1
j(n,m)=c
NEXT m
NEXT n
FOR n=1 TO 3
FOR m=1 TO 3
PRINT j(n,m),
NEXT m
NEXT n
Re: Trouble with 2-dimensional array
Posted: Sat Jan 14, 2017 9:30 pm
by rbytes
It runs OK for me. I have attached my screen output. I named it array.txt.
What happens when you try to run it? Do you get an error, and if so, which line?
Re: Trouble with 2-dimensional array
Posted: Sat Jan 14, 2017 9:32 pm
by sarossell
That's weird. The only way I could get it to work was to change j to j$ throughout.

Is there a variable setting of some sort I'm missing?
Re: Trouble with 2-dimensional array
Posted: Sat Jan 14, 2017 9:41 pm
by sarossell
And now, inexplicably, it's working. Although I suspect an errant TAB somewhere. Apparently, you can't TAB then make an inline comment. Thanks for the confirmation.

Re: Trouble with 2-dimensional array
Posted: Mon Jan 16, 2017 9:31 pm
by GeorgeMcGinn
I too ran your program as-is and it ran fine.
Arrays, unless any element in them contains a string, does not need to be defined as J$.
I too attached my screen print.
George.
Re: Trouble with 2-dimensional array
Posted: Tue Jan 17, 2017 12:56 am
by sarossell
Thanks for checking it out. I went back and checked my code and found that I had left a tab where a comment had been. Apparently sB doesn't like errant tabs.
