By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,097 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,097 IT Pros & Developers. It's quick & easy.

No. of lines in a text file?

P: n/a
How can I determine the total number of lines in a text
file that contains streams of text data, without going
into a loop that reads the lines one by one?

Also, I use the following code to read each line and
proceed to the next one:
'****************************************
Dim sr as StreamReader = New StreamReader("C:\MyFile.TXT")
Dim line as String = sr.ReadLine()
'****************************************
How do I point the reference to line number 75 in the
text file for example without reading the lines one by
one in a loop? And how do I read the last line in the
text file directly?

Thanks
Amjad
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"Amjad" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
How can I determine the total number of lines in a text
file that contains streams of text data, without going
into a loop that reads the lines one by one?

Also, I use the following code to read each line and
proceed to the next one:
'****************************************
Dim sr as StreamReader = New StreamReader("C:\MyFile.TXT")
Dim line as String = sr.ReadLine()
'****************************************
How do I point the reference to line number 75 in the
text file for example without reading the lines one by
one in a loop? And how do I read the last line in the
text file directly?

Thanks
Amjad


ReadAll method.

Split to an array using vbNewLine or vbCrLf as the delimiter.

ArrayName.GetUpperBound(0) + 1 = Number of Lines In File

Mythran
Nov 20 '05 #2

P: n/a
Cor
Hi Amjad,

Can you drink the bottom of your glas first?

Cor
Nov 20 '05 #3

P: n/a

"Cor" <no*@non.com> wrote in message
news:uo*************@TK2MSFTNGP11.phx.gbl...
Hi Amjad,

Can you drink the bottom of your glas first?

Cor

If your using a straw you can... Sorry I couldn't resist
Nov 20 '05 #4

P: n/a
* "Amjad" <an*******@discussions.microsoft.com> scripsit:
How can I determine the total number of lines in a text
file that contains streams of text data, without going
into a loop that reads the lines one by one?

Also, I use the following code to read each line and
proceed to the next one:
'****************************************
Dim sr as StreamReader = New StreamReader("C:\MyFile.TXT")
Dim line as String = sr.ReadLine()
'****************************************
How do I point the reference to line number 75 in the
text file for example without reading the lines one by
one in a loop? And how do I read the last line in the
text file directly?


There is no better way because there is nowhere stored where line number
n starts. You may want to maintain a separate index file, but notice
that all start indices of succeeding lines will change when inserting a
longer/shorter line.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a
Hi Cor,
Yes I can, if I pointed to the bottom of the glass and
made a little hole there!

Amjad
-----Original Message-----
Hi Amjad,

Can you drink the bottom of your glas first?

Cor
.

Nov 20 '05 #6

P: n/a
Cor
LOL

You are right there was something wrong with this text

If your using a straw you can... Sorry I couldn't resist

Nov 20 '05 #7

P: n/a
Cor
Hi Amjad,
Yes I can, if I pointed to the bottom of the glass and
made a little hole there!
Can you drink the bottom of your glas first?


That was an answer I did wanted to reply,

Because I did wanted to answer is it worth that much work for such a simple
thing

Cor
Nov 20 '05 #8

P: n/a
surely this is a function of the glass object?? I presume you need to
implement a drinkfrombottom() method?

Regards
Simon
"Cor" <no*@non.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
Hi Amjad,
Yes I can, if I pointed to the bottom of the glass and
made a little hole there!
Can you drink the bottom of your glas first?

That was an answer I did wanted to reply,

Because I did wanted to answer is it worth that much work for such a

simple thing

Cor

Nov 20 '05 #9

P: n/a
Alright now I think we all need to go home and have a drink, but remember
drink it from the bottom of the glass and give a detailed explination of how
you did it after the holiday.. :)

Merry Christmas..

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
surely this is a function of the glass object?? I presume you need to
implement a drinkfrombottom() method?

Regards
Simon
"Cor" <no*@non.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
Hi Amjad,
Yes I can, if I pointed to the bottom of the glass and
made a little hole there!

>Can you drink the bottom of your glas first?
>


That was an answer I did wanted to reply,

Because I did wanted to answer is it worth that much work for such a

simple
thing

Cor


Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.