Is there an easy way to save then reload a multi-dimensional array to and from a file?
In this case it's a 3D array.
I just tried Put and Get, but they didn't seem to work.
Printable View
Is there an easy way to save then reload a multi-dimensional array to and from a file?
In this case it's a 3D array.
I just tried Put and Get, but they didn't seem to work.
Like this? or you are using a dynamic array?
VB Code:
private Arr(2, 2, 2) As String Private Sub getArray() Open "C:\myfile.txt" For Binary As #1 Get #1, , Arr Close #1 End Sub Private Sub SaveArray() Open "C:\myfile.txt" For Binary As #1 Put #1, , Arr Close #1 End Sub
If you're using a dynamic array:
VB Code:
private Arr() As String Private Sub getArray() Dim lngDim(2) As Long Open "C:\myfile.txt" For Binary As #1 ' read the dimensions (12 bytes totaling of three Long values) Get #1, , lngDim ' clear array in case Arr is already filled with something Erase Arr ' initialize ReDim Arr(lngDim(0), lngDim(1), lngDim(2)) ' fill the array Get #1, , Arr Close #1 End Sub Private Sub SaveArray() Open "C:\myfile.txt" For Binary As #1 ' store dimensions as three long values (each one is 4 bytes) Put #1, , CLng(UBound(Arr, 1)) Put #1, , CLng(UBound(Arr, 2)) Put #1, , CLng(UBound(Arr, 3)) ' store the actual array Put #1, , Arr Close #1 End Sub
Code is untested as I don't have VB on this machine; and I guess string arrays can be saved directly (I've never tried it myself, I like defining things more precisely; and I never use multidimension arrays anyway).
Working Great!
Thx Merri