In addition to the ways already discussed, there are several additional ways that I can think of:
1. if the arrays are identical, then pass the relevant array pointers to your functions instead of the name.
type MyArray_t
Greeting as string
endtype
dim Array1(10) as MyArray_t
dim Array2(10) as MyArray_t
Array1Ptr = get arrayptr( Array1() )
Array2Ptr = get arrayptr( Array2() )
UpdateArray( Array1Ptr, 0, "Hello" )
UpdateArray( Array2Ptr, 0, "Goodbye" )
print Array1(0).Greeting
print Array2(0).Greeting
wait key
end
function UpdateArray(a as dword, i as integer, s as string)
local dim Array() as MyArray_t ` Define an empty local array
link array Array(), a ` Connect the pointer to the local array
Array(i).Greeting = s ` Now update the array
unlink array Array() ` Disconnect the array from the local array
endfunction
2. use my in-memory lookup commands to simulate an array.
make lookup 1 ` Simulate first array
make lookup 2 ` Simulate second array
UpdateArray( 1, 0, "Greeting", "Hello" )
UpdateArray( 2, 0, "Greeting", "Goodbye" )
print GetArray( 1, 0, "Greeting" )
print GetArray( 2, 0, "Greeting" )
wait key
end
function UpdateArray( id as integer, i as integer, field as string, s as string )
set lookup id, padleft$(str$(i), "0", 9) + field , s
endfunction
function GetArray( id as integer, i as integer, field as string)
exitfunction lookup$(id, padleft$(str$(i), "0", 9) + field)
endfunction ""
3. if the arrays are different, then call different functions via function pointers
type MyArray1_t
Greeting as string
endtype
type MyArray2_t
Other as string
endtype
dim Array1(10) as MyArray1_t
dim Array2(10) as MyArray2_t
Update( "Array1", 0, "Hello" )
Update( "Array2", 0, "Goodbye" )
print Array1(0).Greeting
print Array2(0).Other
wait key
end
function Update(a as string, i as integer, s as string)
call function name "Update" + a, i, s
endfunction
function UpdateArray1(i as integer, s as string)
Array1(i).Greeting = s
endfunction
function UpdateArray2(i as integer, s as string)
Array2(i).Other = s
endfunction
... and given a couple of hours, I could probably come up with several other methods too.