Trouble with 2-dimensional array

Post Reply
User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Trouble with 2-dimensional array

Post 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
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Trouble with 2-dimensional array

Post 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?
Attachments
IMG_9360.PNG
IMG_9360.PNG (68.21 KiB) Viewed 2635 times
The only thing that gets me down is gravity...

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Trouble with 2-dimensional array

Post 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?
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Trouble with 2-dimensional array

Post 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. :)
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Trouble with 2-dimensional array

Post 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.
Attachments
IMG_1053.PNG
IMG_1053.PNG (76.3 KiB) Viewed 2603 times
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Trouble with 2-dimensional array

Post 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. ;)
smart BASIC Rocks!

- Scott : San Diego, California

Post Reply