På vore dages pc´er er det ikke noget problem at indlæse en sekventiel fil, hver mindre den er rigtig rigtig stor. Så du kan sagtens indlæse en sekventiel fil i et array.
Jeg har testet med en fil, med 100.000 linier - Det tager 0.25 sekunder at skrive og indlæse denne.
Private Sub Command1_Click()
' Skriv test sekventiel fil
Dim tid As Variant
tid = Timer
Dim i As Long
Open "C:\temp\xxx.txt" For Output As #1
For i = 1 To 100000
Print #1, Timer
Next
Close
MsgBox "Forbrugt tid: " & Timer - tid
End Sub
Private Sub Command1_Click()
' Skriv test sekventiel fil
Dim tid As Variant
tid = Timer
Dim i As Long
Open "C:\temp\xxx.txt" For Output As #1
For i = 1 To 100000
Print #1, i
Next
Close
MsgBox "Forbrugt tid: " & Timer - tid
End Sub
Private Sub Command2_Click()
' Indlæs sekventiel fil
Dim tid As Variant
tid = Timer
Dim sLines() As String
ReDim sLines(0)
Dim nLines As Long
nLines = -1
Open "C:\temp\xxx.txt" For Input As #1
Do While Not EOF(1)
nLines = nLines + 1
ReDim Preserve sLines(nLines)
Line Input #1, sLines(nLines)
Loop
Close
MsgBox "Forbrugt tid: " & Timer - tid & vbNewLine & "Antal Linier " & nLines
IndSaetLinie "Hello World", 8, sLines, nLines
SletLinie 5, sLines, nLines
Open "C:\temp\xxx.txt" For Output As #1
For i = 0 To nLines
Print #1, sLines(i)
Next
Close
End Sub
Sub SletLinie(iSletDenne As Long, sLines() As String, nLines As Long)
Dim i As Long
nLines = nLines - 1
For i = iSletDenne - 1 To nLines
sLines(i) = sLines(i + 1)
Next
ReDim Preserve sLines(nLines)
End Sub
Sub IndSaetLinie(sText As String, iFoerDenne As Long, sLines() As String, nLines As Long)
Dim i As Long
nLines = nLines + 1
ReDim Preserve sLines(nLines)
For i = nLines To iFoerDenne Step -1
sLines(i) = sLines(i - 1)
Next
sLines(iFoerDenne - 1) = sText
End Sub
Mvh
Michael Christoffersen