473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

No. of lines in a text file?

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
9 1563

"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
Cor
Hi Amjad,

Can you drink the bottom of your glas first?

Cor
Nov 20 '05 #3

"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
* "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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: BadOmen | last post by:
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible? Then when I read the...
2
by: Jesse Noller | last post by:
I am a relative newbie to python and I am having issues trying to iterate over the lines of a file. I have a text file - foo.bar inside of this file are lines of text: x-3411342 y-1324123...
6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
4
by: MJ | last post by:
Currently i am using the below coding to create a text file and write something on it. Dim wfile As New System.IO.StreamWriter("c:\test.txt" wfile.WriteLine("Hello" & vbcrlf & "Are" & vbcrlf &...
18
by: Vasilis Serghi | last post by:
Presently I define the number of lines to be expected in a file when defining the array size and the initialisation of this array. This works fine for now, but i'm sure that in the future this...
7
by: TheGanjaMan | last post by:
Hi people, I'm stuck on a problem and I was wondering if there was a way around: I'm trying to find the number of lines in a comma delimited text file. I have a progress bar that should...
6
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would...
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.