Read a text file from a specific line at to the and

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

Read a text file from a specific line at to the and

Post by sal21 »

For example...

Number_of_line=5000

Read TXT from Lines Number 5001, to the and of file

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

Re: Read a text file from a specific line at to the and

Post by HansV »

Loop through the file line by line, and simply don't do anything with the first 5000 lines.

Code: Select all

    Dim f As Integer
    Dim i As Long
    Dim s As String
    f = FreeFile
    Open "..." For Input As #f
    Do While Not EOF(f)
        Line Input #f, s
        i = i + 1
        If i > 5000 Then
            ' do something with s
        End If
    Loop
    Close #f
Best wishes,
Hans

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

Re: Read a text file from a specific line at to the and

Post by sal21 »

HansV wrote:
02 Dec 2021, 21:25
Loop through the file line by line, and simply don't do anything with the first 5000 lines.

Code: Select all

    Dim f As Integer
    Dim i As Long
    Dim s As String
    f = FreeFile
    Open "..." For Input As #f
    Do While Not EOF(f)
        Line Input #f, s
        i = i + 1
        If i > 5000 Then
            ' do something with s
        End If
    Loop
    Close #f
HERE: Line Input #f, s

Error in image
You do not have the required permissions to view the files attached to this post.

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

Re: Read a text file from a specific line at to the and

Post by HansV »

Is the text file a single line, perhaps?
Best wishes,
Hans

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

Re: Read a text file from a specific line at to the and

Post by sal21 »

HansV wrote:
02 Dec 2021, 21:56
Is the text file a single line, perhaps?
No.
Test1 in One of my last post, around JSON big file.

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

Re: Read a text file from a specific line at to the and

Post by HansV »

It probably has to do with the rest of your code. The code listed above should not cause problems.
Best wishes,
Hans

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

Re: Read a text file from a specific line at to the and

Post by sal21 »

The test1 Is a cut and past from original big file.
The big file Is stored in the dir, refered To the error in this post.

But i have maked An esperiment...
I loop the big file wiht a fso stream And dont have error!
Peraph each Lines in file dont have a crlf on each line....
No idea.

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

Re: Read a text file from a specific line at to the and

Post by HansV »

There is a CrLf at the end of every line in the small file that you attached.
But you could use the same idea for the FSO Stream.
Best wishes,
Hans

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

Re: Read a text file from a specific line at to the and

Post by sal21 »

Ok