View Single Post
 
Old 01-15-2014, 08:20 PM
omahadivision omahadivision is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default

I also thought that I would post the code in case anyone else in the future tries a similar method:

Counts whole file (megacount is the new counter I made to create the entire file)

Code:
Do While Not fo.AtEndOfStream 'Counts all lines
fo.readline
Megacount = Megacount + 1
Loop
Close and reopen:

Code:
fo.Close
Set fo = fso.OpenTextFile(FName, 1)
Getting the end of the array:

Code:
countagain=0 'This is required to count what line the file is on during the second run
Count=0

If Megacount < 10000 Then 'For small files under 10000 lines, entire array is imported
       Do While Not fo.AtEndOfStream 'Puts the rest of the file into an array after title line
       Count = Count + 1
       ReDim Preserve AllArray(Count)
       AllArray(Count) = fo.readline
       Loop
       
    Else 'Bigger files above 10000 lines.  'Cycles through beginning of file without putting anything in array
        Do Until Countagain > Megacount - 9999
        fo.readline
        Countagain = Countagain + 1
        Loop
        
        Do While Not fo.AtEndOfStream 'Actually puts things in array, Count is the array counter
        ReDim Preserve AllArray(Count)
        AllArray(Count) = fo.readline
        Count = Count + 1
        Loop
 End If
The advantage of using three counters (Count, countagain, megacount) instead of two is that the first imported line (10,000 from end of file) is in AllArray(0), and the last line is in AllArray(Count)
Reply With Quote