[code=thinbasic]
'
' Example of function to handle both one and two dimensional arrays.
' Error message when one dimensional array passed as two dimensional:
' "Missing Close Parens ')'. Expected a ')' but found something else."
'

USES "console"

ALIAS CONSOLE_WRITE AS write
ALIAS CONSOLE_READLINE AS read

CONST NL AS STRING * 2 VALUE $crlf

DIM array2( 9, 9 ) AS INTEGER VALUE 7
DIM array1( 9 ) AS INTEGER VALUE 2

array1( 1 ) = 3
array1( 6 ) = 9
array2( 5, 5 ) = 4
array2( 2, 6 ) = 8

write NL, " A nine-vector displayed as a 3x3 matrix:", _
NL,"CALL digitarrayshow( array1, 9, 0, 3 )", NL

CALL digitarrayshow( array1, 9, 0, 3 )

write NL, "A 9x9 matrix displayed by the same function: ", _
NL,"CALL digitarrayshow( array2, 9, 9, 9 )",NL

CALL digitarrayshow( array2, 9, 9, 9 )

write NL, "A nine-vector shown as a row vector:", _
NL,"CALL digitarrayshow( array1, 9, 0, 9 )",NL

CALL digitarrayshow( array1, 9, 0, 9 )

write NL, "A nine-vector shown as a column vector:", _
NL, "CALL digitarrayshow( array1, 9, 0, 0 )"

CALL digitarrayshow( array1, 9, 0, 0 )

write NL

'"Missing Close Parens ')'. Expected a ')' but found something else."
'Uncomment next line to generate error code 20 message.
'call digitarrayshow(array1,9,9,9)


write "press enter to close window"

read( )

STOP

FUNCTION digitarrayshow( data_array( ) AS INTEGER, maxdim1 AS INTEGER, maxdim2 AS INTEGER, breakcount AS INTEGER )
LOCAL idim1 AS INTEGER
LOCAL idim2 AS INTEGER
'
IF maxdim1 < 1 THEN
EXIT FUNCTION
ENDIF
FOR idim1 = 1 TO maxdim1
IF maxdim2 > 0 THEN
FOR idim2 = 1 TO maxdim2
IF MOD ( idim2, breakcount ) = 1 OR breakcount < 2 THEN
write NL
ENDIF
write data_array( idim1, idim2 ), " "
NEXT
ELSE
IF MOD ( idim1, breakcount ) = 1 OR breakcount < 2 THEN
write NL
ENDIF
write data_array( idim1 ), " "
ENDIF
NEXT
write NL
END FUNCTION

[/code]