List Info

Thread: Re: To read the 100th line from textfile




Re: To read the 100th line from textfile
country flaguser name
United States
1969-12-31 18:00:00

Hi,

Sample code. Hope it helps.Do add reference to "Microsoft Scripting Runtime" before trying the same.

----------------------------------------------------------
Dim fs As Scripting.FileSystemObject
Dim ts As Scripting.TextStream

Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(<filename>;, ForReading, False)

'find out how many records are there in the file
Do While ts.AtEndOfStream <> True
ts.SkipLine
totRec = totRec + 1
Loop
ts.Close

totRec = totRec - 100 '
If totRec > 0 Then ' this is to check if you have more than 100 lines , hence proceed.

'Now reopen the file for actual processing
Set ts = fs.OpenTextFile(<filename>;, ForReading, False)

' Skipping lines to reach the first data line
For i = 0 To 99
ts.SkipLine
Next i
'you are on the 100th line , do u action here
end if



----------------------------------------------------------

regards,
Ashish.0.

MohdAfseer < issa_luverboy%40yahoo.co.uk">issa_luverboyyahoo.co.uk> wrote:
Hi all,

I have a problem in string search. I want it to read it from the 100th
line at the start only. Give me example.

Do help me friends

Regards,

Afseer

---------------------------------
Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )