Forum
Declare an array type - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Declare an array type (/showthread.php?tid=2575)



Declare an array type - baltasarq - 11-22-2024

How do you declare an array type? I supposed it should be easy to find in the docs, but didn't have any luck. For instance:
Code:
sub doThis(v as string?)
    print( v( 0 ) )
endsub
I'm certain it is not string() (I have tried that). I wonder if I have to use DIM again?
Thanks,
-- Baltasar


RE: Declare an array type - boriel - 11-22-2024

I think you mean passing an array as a parameter.
This is indeed a bit hidden in the docs: https://zxbasic.readthedocs.io/en/docs/byref/

The syntax is
Code:
Sub doThis(v() as String)
  ...
End Sub

Note that v() can be ANY array of strings of ANY dimensions. You'll have to use LBOUND and UBOUND to retrieve the dimensions of the array if you are expecting arrays of different dimensions.


RE: Declare an array type - baltasarq - 11-22-2024

Great, thanks!!