I want to copy a two-dimensional array (8,8) in Picomite. Since I want to do this several times in a row with different source and target arrays, I want to use a function.
Unfortunately, I keep getting error messages at the call (syntax and dimensions) and can’t find any examples in the manual.
Here is the function:
Function Raster_kopieren(Quelle As Integer(1 to 8, 1 to 8)) As Integer(1 to 8, 1 to 8) Dim arrErgebnis(8, 8) As Integer Dim r As Integer, c As Integer For r = 1 To Zeilen For c = 1 To Spalten arrErgebnis(r, c) = Quelle(r, c) Next c Next r Return arrErgebnis End Function
Here is the call:
temporaeres_Raster() = Raster_kopieren(intWert(1 to 8, 1 to 8))
I don’t understand what you are trying to do but this isn’t remotely valid syntax. The way to pass an array to a function is Quelle(). Also, MMBasic can’t return arrays from a function. To modify an array in a function you need to include it in the argument list. All arrays are passed by reference so any changes made in the function will be then be seen outside. You also need to understand OPTION BASE and use it as appropriate for your application.
You don’t need to include arrays in the parameter list. Arrays (and any other variables) defined in the main program are global so any changes made to the array in a SUB or FUNCTION will still be there when the SUB or FUNCTION returns.
Agreed. Pass by reference is in many cases a better choice than directly accessing something as a global, as it allows using the same subroutine/function to be used with multiple things in a controlled fashion.