Hi Cliff,
Is there a specific need to save it to a separate file? If so: To read
and write from/to disk you can use the TextStream object and the ReadLine,
Read, Write, or Writeline methods. Do a search for those words in the VBA
help. Or you can use the Input #, Print #, Write # with a file opened with
the Open statement. These would probably be easier to use than the Put # and
Get # statements which operate at more detailed level than you probably need.
If you do not need to save it to a separate file, you could just save it
in a table that might look something like this:
tblMyArray
X_Coordinate
Y_Coordinate
Z_Coordinate
The_Value
If it is a sparse array, you could save only those items that contain
values. Then when you need to reload it, initialize your array variable
first, and then load the values from the table. Air code, not complete.
Public Sub CreateAndSaveArray()
Dim rs As DAO.Recordset
Dim intarrValues(20, 30, 40) As Integer
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
' Stuff that populates the array
' Save the array
' Open the table as a recordset
' Use three nested For...Next loops to go through the array and save
' each value as a record in the table
For intX = 1 To 20
For intY = 1 To 30
For intZ = 1 To 40
rs.Add
rs!X_Coordinate = intX
rs!Y_Coordinate = intY
rs!Z_Coordinate = intZ
rs!The_Value = intarrValues(intX, intY, intZ)
rs.Update
Next intZ
Next intY
Next intX
' Close the recordset
End Sub
Public Sub LoadAndUseArray()
Dim rs As DAO.Recordset
Dim intarrValues(20, 30, 40) As Integer
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
' Load the array
' Use three nested For...Next loops to go through the array and clear all
values
' Open the table as a recordset (i.e. named rs)
' Read each record and place value in array
Do While Not rs.EOF
intarrValues(rs!X_Coordinate, rs!Y_Coordinate, rs!Z_Coordinate) = rs!
The_Value
rs.MoveNext
Loop
' Close the recordset
' Stuff that uses the array
End Sub
Hope this helps,
Clifford Bass