View Single Post
 
Old 01-14-2014, 08:15 PM
omahadivision omahadivision is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default Is there a way to delete the beginning part of an array so it doesn't overflow?

Hi Guys,

So I need to import a large text file into an array. I only need the last 5,000 lines or so. Most of the files are ok, but occasionally (around 30000 lines) I get an overflow error. Since I only need the last five thousand lines or so, is there a way to delete the beginning part of the array as more is added after 5,000 lines, I.E. when line 5001 is imported line 1 gets erased? I tried the below but still got the overflow error. I wouldn't have to delete pieces of the array one at a time, either - I could say that at 10,000 the first 5000 get deleted, at 15,000 the next 5000 get deleted, etc. Or might I just be better off reading the file twice to count the lines?

Code:
       Do While Not fo.AtEndOfStream
       Count = Count + 1
       ReDim Preserve AllArray(Count)
       AllArray(Count) = fo.ReadLine
       'If Count > 5000 Then AllArray(Count - 5000) = ""
       Loop
Thanks!
Reply With Quote