DIM statement in SmallBASIC

Started by dp2macrae, June 07, 2022, 05:19:53

Previous topic - Next topic

dp2macrae

A question from a newbie. I am trying to DIM a one-dimensional array. I've tried:

DIM names ( 1 TO 9 )
DIM names ( 10 )
DIM names [ 10 ]

When I populate the arrays, everything seems fine, that is until I try to use the array in a FOR statement, like this:

FOR i = 1 TO 9
  PRINT names ( i )
NEXT

I get the following error:

Expr/RT: Variable is NOT an array (Use DIM)

What am I doing wrong? Thanks in advance.

dp2macrae

#1
I have figured it out. In the original code in the PRINT statement, the first thing in the PRINT statement was SPACES ( 5 ) instead of SPACE ( 5 ).

Having said that, can I use DIM names ( 10 ) instead of DIM names ( 1 TO 9 )?

J7M

Two different ways to initialize an array. Depends on the indexes you want to use:

dim A(2 to 5)   -> A[2], A[3], A[4], A[5]
dim B(3)          -> B[0], B[1], B[2], B[3]

accessing other elements of the arrays would return an error.