jump directly to the line 457478

sorry for my bad English.


i have a text with 132 fixed length lines.

i need to jump directly to the line number 457478.

but not with the a loop line by line... i know this way, i need to jump directly the line  457478.

Now after the code is in line number 457478, read, line-by-line, the rest of text to the end of text

Note:
The text file has approx 4500000 (4.5M) lines and the file size is approx 533 MB
tina2009Asked:
Who is Participating?
 
aikimarkCommented:
For example purposes, I've attached a sample fixed length file.  It only has 400 records.

The following routine accepts a starting record number as a parameter value and uses the Seek statement to position the 'cursor'.  Although each line is only 19 characters long, the length of the line used for calculating the offset, includes the vbCrLf characters that terminate/delimit the lines.
Option Explicit

Sub Q_28654444(parmStartLine As Long)
    Dim intFN As Integer
    Dim strLineData As String
    Const cRecLen As Long = 21
    intFN = FreeFile
    Open "c:\users\aikimark\downloads\Fixed Length Data.txt" For Input As #intFN
    Seek #intFN, (cRecLen * parmStartLine) + 1
    Do Until EOF(intFN)
        Line Input #intFN, strLineData
        Debug.Print Right(strLineData, 3), ;
    Loop
    Debug.Print
    Close
End Sub

Open in new window

If you needed to read the line before you started looping, you would add an extra Line Input statement.
Fixed-Length-Data.txt
0
 
aikimarkCommented:
@tina2009

Since these are fixed length lines, you have at least two solutions.
VB instrinsic solution 1
Open the file as Input
Calculate the position in the file = (record size * 457478)
Use the Seek statement to position the 'cursor' in the file
Use Line Input statement to read the rest of the file

VB instrinsic solution 2
Open the file as Binary or Random
Calculate the position in the file = (record size * 457478)
Use the Get statement to position the 'cursor' in the file
Use Get statement to read the rest of the file

FileSystemObject solution
Open the file and instantiate a textstream object
Calculate the position in the file = (record size * 457478)
Use the textstream's Skip method to position the 'cursor' in the file
Use textstream's readline method to read the rest of the file
0
 
tina2009Author Commented:
not for me....:-(

can you post a simple code for all ttree possible solution?
Tks.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
aikimarkCommented:
Do you know how to program/code?
0
 
tina2009Author Commented:
Sure! but my knoledgment of vb6 not is so advanced:-)
0
 
aikimarkCommented:
With what programming languages are you familiar?

Have you pressed F1 and read the help text for the Open statement or Line Input statement or the Seek statement?

Have you done an online search of the FileSystemObject or the TextStream object?

can you post a simple code for all ttree possible solution?
While I could do that, I'm not going to.  I might post one, but I don't know the context/application in which you are coding.

Some effort on your part will go a long way when working with the experts.

The volunteer experts are here to help you.  If you need a professional to do all the work for you, look at the top experts in the VB zone and see if any of them have enabled their Hire Me link.
0
 
tina2009Author Commented:
No good devolution...
blahhnh
0
 
aikimarkCommented:
I don't understand your comment
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.