To read and write data quickly from arrays to file (or vice-versa)
consider using Put and Get. This is significantly faster than reading and writing the
array one entry at a time using Input #, Write # or Print #. The example below
writes the entire contents of an array to a file in one step.
Dim arrLongValue(1 To 100000) As Long
Dim IntNum As Integer
'populate array here
IntNum = FreeFile
Open "C:\Temp\Test.dat" For Binary As intNum
Put #intNum, arrLongValue
Close intNum
For files contain data of different data types, consider using a user defined variable
into which each file line can be read. See example below:
' Define user-defined type.
Type Record
ID As Integer
Name As String * 20
End Type
Dim MyRecord As Record, Position
' Open sample file for random access.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
' Define record number.
Position = 3
' Read third record.
Get #1, Position, MyRecord
Close #1
|