loop into array

User avatar
sal21
PlatinumLounger
Posts: 4347
Joined: 26 Apr 2010, 17:36

loop into array

Post by sal21 »

2 question...
1- how to loop the array A just created from code (line by line)
2- the code work with a file arround 25mg but if have a file arround 2 gb?

Code: Select all

Sub TRE()

Dim A() As Long
Dim Test As String ' IS MY LINE

Open "C:\TEMP\TEST.TXT" For Binary As #1
ReDim A(0 To LOF(1) - 1)
Get #1, , A
Close #1

End Sub

User avatar
HansV
Administrator
Posts: 78405
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: loop into array

Post by HansV »

Why do you want to do this? You're trying to load an entire disk file into memory! With 2GB that's a bit much...
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4347
Joined: 26 Apr 2010, 17:36

Re: loop into array

Post by sal21 »

HansV wrote:Why do you want to do this? You're trying to load an entire disk file into memory! With 2GB that's a bit much...
i m sorry.... 20 mb no 2gb

User avatar
HansV
Administrator
Posts: 78405
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: loop into array

Post by HansV »

The line

Get #1, , A

loads the file into memory as one big array, not as a series of lines. What exactly do you want to do?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4347
Joined: 26 Apr 2010, 17:36

Re: loop into array

Post by sal21 »

HansV wrote:The line

Get #1, , A

loads the file into memory as one big array, not as a series of lines. What exactly do you want to do?
STORE into array the complete txt file (line by line) and loop similar Ubound Lbonud ecc...

I think is a good way to work with a big number of lines , or not?

User avatar
HansV
Administrator
Posts: 78405
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: loop into array

Post by HansV »

I think it's easier to read the file line by line, for if you open it as binary, you have to go through it character by character instead of line by line.
Best wishes,
Hans