' Assumption: The 3D array is of DOUBLE data type and you know the dimensions.
SUB Save3DArrayToFile(BYREF array() AS DOUBLE, BYVAL xSize AS LONG, BYVAL ySize AS LONG, BYVAL zSize AS LONG, ByVal sFileName AS STRING)
LOCAL fNum AS LONG
LOCAL i AS LONG, j AS LONG, k AS LONG
LOCAL sLine AS STRING
' Attempt to open the file for output.
fNum = FREEFILE
OPEN sFileName FOR OUTPUT AS #fNum
IF ERR THEN
' Handle file open error.
PRINT "Error opening file."
EXIT SUB
END IF
' Write the array size at the beginning. (Optional but useful for reading back the array)
PRINT #fNum, USING$("Dimensions: #, #, #", xSize, ySize, zSize)
' Write the array data to the file.
FOR i = 1 TO xSize
FOR j = 1 TO ySize
FOR k = 1 TO zSize
' Write each element to a line.
' You could use a different format or delimiters as per your need.
PRINT #fNum, USING$("Array(#, #, #): #", i, j, k, array(i, j, k))
NEXT k
NEXT j
NEXT i
' Close the file.
CLOSE #fNum
END SUB
Keep in mind that this function assumes you are working with arrays that have their indices starting from 1. Depending on your array initialization, you may need to adjust the loops if your arrays are 0-based. Also, the use of USING$ is for formatted output, you can use a different method or simply concatenate strings for writing.
DIM MyArray(1 TO 10, 1 TO 10, 1 TO 10) AS DOUBLE
' ... Populate your array ...
Save3DArrayToFile(MyArray(), 10, 10, 10, "MyArrayData.txt")
Please adapt the function according to your specific requirements, array data type, and error-handling preferences. The above example is a starting point and may require adjustments for practical usage.