|
-
Aug 17th, 2006, 09:31 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] saving a multi-dimensional array to file?
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.
-
Aug 17th, 2006, 10:21 PM
#2
Re: saving a multi-dimensional array to file?
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
-
Aug 18th, 2006, 01:33 AM
#3
Re: saving a multi-dimensional array to file?
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).
-
Aug 18th, 2006, 11:17 AM
#4
Thread Starter
Frenzied Member
Re: saving a multi-dimensional array to file?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|