ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Way to free memory as I input lines from a file? (https://www.excelbanter.com/excel-programming/308745-way-free-memory-i-input-lines-file.html)

Steven Douglas

Way to free memory as I input lines from a file?
 
Hi,

I have some code where I open a very large file into
memory then enter a loop where I input each line one by
one, analyse it & draw data from it depending on certain
criteria.

The file being opened is 216,000 lines long and when the
code is running it just seems to get slower and slower
the further down the file it gets.

My question is, can I speed it up? I'm no expert, but
what I presume is happening is that Excel is, line by
line, opening more and more of the file into memory and
keeping it there. If that's the case, is there a way of
releasing the memory (of the lines) i no longer need?

I don't totally understand what the Filehandle & Freefile
things are, I just know that they work. In fact, would it
be quicker to use (Open openfile For Binary Access Read
As #Filehandle) & return data from the file that way?
(it's all the same place).

Any help on this would be greatly appreciated!

Thanks for your time,

Steven Douglas

Below is a very cut down version of the loop I'm running,
there are lot of other IF's & Do__Loop statements in
there, and I have them running as efficiently as possible.

'------------------------------------------------------

openfile = strDir & strBureau & "\XND.CSV"
Filehandle = FreeFile()

Open openfile For Input As #Filehandle

Do
Line Input #Filehandle, strData

If Mid(strData, 2, 1) = "A" Then
varkWh(1) = Mid(strData, 71, 8)
varkWh(2) = Mid(strData, 55, 13)
varkWh(3) = Mid(strData, 82, 30)
End If

'CAN i PUT A LINE HERE TO RELEASE MEMORY

Loop Until EOF(1)
'------------------------------------------------------





GJones

Way to free memory as I input lines from a file?
 
Hi Steven;

You can use a text driver to query the CSV file for the
exact information you want. Look at this link


http://4guysfromrolla.com/webtech/030899-1.shtml

Thanks,

Greg
-----Original Message-----
Hi,

I have some code where I open a very large file into
memory then enter a loop where I input each line one by
one, analyse it & draw data from it depending on certain
criteria.

The file being opened is 216,000 lines long and when the
code is running it just seems to get slower and slower
the further down the file it gets.

My question is, can I speed it up? I'm no expert, but
what I presume is happening is that Excel is, line by
line, opening more and more of the file into memory and
keeping it there. If that's the case, is there a way of
releasing the memory (of the lines) i no longer need?

I don't totally understand what the Filehandle & Freefile
things are, I just know that they work. In fact, would it
be quicker to use (Open openfile For Binary Access Read
As #Filehandle) & return data from the file that way?
(it's all the same place).

Any help on this would be greatly appreciated!

Thanks for your time,

Steven Douglas

Below is a very cut down version of the loop I'm running,
there are lot of other IF's & Do__Loop statements in
there, and I have them running as efficiently as possible.

'------------------------------------------------------

openfile = strDir & strBureau & "\XND.CSV"
Filehandle = FreeFile()

Open openfile For Input As #Filehandle

Do
Line Input #Filehandle, strData

If Mid(strData, 2, 1) = "A" Then
varkWh(1) = Mid(strData, 71, 8)
varkWh(2) = Mid(strData, 55, 13)
varkWh(3) = Mid(strData, 82, 30)
End If

'CAN i PUT A LINE HERE TO RELEASE MEMORY

Loop Until EOF(1)
'------------------------------------------------------




.



All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com