473,241 Members | 1,750 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,241 software developers and data experts.

Wring a VB.NET object to count lines in a text file

Team VB.net,

I have multiple programs that need a tool to count lines in a text
files. I have been solving this problem through writing proceedures
but I hate cutting and pasting code.

Is there an easy way of making a "module" or object that I would be
able to pass a string variable "c:\MyTextFile" to and then have it run
this proceedure on it?
It seems like I need to write a COM to do this, but I have yet to find
an easy tutorial on this subject.....

Any direction or tutorial links you have would be greatly appreciated.

-Peter
Nov 20 '05 #1
5 7366
"Peter" <pe***@mclinn.com> schrieb
Team VB.net,

I have multiple programs that need a tool to count lines in a text
files. I have been solving this problem through writing
proceedures but I hate cutting and pasting code.
What does writing proceudres have to do with cutting and pasting code? It's
sufficient to write it once.
Is there an easy way of making a "module" or object that I would
be able to pass a string variable "c:\MyTextFile" to and then have it
run this proceedure on it?
Yes, write a module or a class and add the procedure. I prefer a class.
It seems like I need to write a COM to do this, but I have yet to
find an easy tutorial on this subject.....
COM? No, you don't need COM.
Any direction or tutorial links you have would be greatly
appreciated.


Class CountTextFileLines
Public Shared Function Start(ByVal filename As String) As Integer
Dim fs As IO.FileStream
Dim sr As IO.StreamReader
Dim Result As Integer

fs = New IO.FileStream( _
filename, IO.FileMode.Open, _
IO.FileAccess.Read, IO.FileShare.Read _
)

sr = New IO.StreamReader(fs)

Do
If sr.ReadLine Is Nothing Then Exit Do
Result += 1
Loop

Return Result
End Function
End Class
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #2
I wanted to respond to one line...

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
"Peter" <pe***@mclinn.com> schrieb
Team VB.net,

I have multiple programs that need a tool to count lines in a text
files. I have been solving this problem through writing
proceedures but I hate cutting and pasting code.
What does writing proceudres have to do with cutting and pasting code?

It's sufficient to write it once.
Is there an easy way of making a "module" or object that I would
be able to pass a string variable "c:\MyTextFile" to and then have it
run this proceedure on it?


Yes, write a module or a class and add the procedure. I prefer a class.
It seems like I need to write a COM to do this, but I have yet to
find an easy tutorial on this subject.....


COM? No, you don't need COM.


Hehe... thats just funny,
Any direction or tutorial links you have would be greatly
appreciated.


Class CountTextFileLines
Public Shared Function Start(ByVal filename As String) As Integer
Dim fs As IO.FileStream
Dim sr As IO.StreamReader
Dim Result As Integer

fs = New IO.FileStream( _
filename, IO.FileMode.Open, _
IO.FileAccess.Read, IO.FileShare.Read _
)

sr = New IO.StreamReader(fs)

Do
If sr.ReadLine Is Nothing Then Exit Do
Result += 1
Loop

Return Result
End Function
End Class
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
"CJ Taylor" <no****@blowgoats.com> schrieb
I wanted to respond to one line...


And why don't you only quote the one line? SCNR to ask.

COM? No, you don't need COM.


Hehe... thats just funny,

Ok, "...not for this purpose."

:)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
ok. I build this and get a dll.

Now how do I refrence it?

I went to add refrence and found the dll.

What is the sytax I should be using to sent the data to this dll...

IE.. mydll("c:\test.text")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5
Well... your reference will give you the dll namespace, and then you just
execute a function within that DLL as if it was part of another class within
your program.

Given I don' t know what your DLL reference is like, the namespace, or the
methods you use I can't give you a specific example. However, I can do
this.

if your dll has the namespace myDLL (that is probably the project name for
you) and you add a reference you can access that. Now just the DLL is
useless (excuse me, I shouldn't use the word DLL as it can lead to some
confusion, its a .NET Assembly with the extension DLL. Many of the same
features but unlike classic DLL's (Regular DLL's or ActiveX DLL's) these can
only run in a managed environement.

so, you have MyDLL, and lets say you have MyFunction as a method of that
dll.

In your main program you would simply call

returnval = MyDLL.MyFunction("C:\testfile.txt")

this is all dependent on what you have in there though. =)

-CJ

"Peter McLinn" <pm*****@mclinn.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
ok. I build this and get a dll.

Now how do I refrence it?

I went to add refrence and found the dll.

What is the sytax I should be using to sent the data to this dll...

IE.. mydll("c:\test.text")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard | last post by:
Hi, Can anyone tell me what the difference is between for line in file.readlines( ): and for line in file:
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: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a...
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
28
by: John Salerno | last post by:
What is the best way of altering something (in my case, a file) while you are iterating over it? I've tried this before by accident and got an error, naturally. I'm trying to read the lines of a...
8
by: shivam001 | last post by:
I have the following file as the input APPLE 0 118 1 110 1 125 1 135 2 110 3 107 3 115 3 126 ORANGE 0 112 1 119 2 109 2 119 3 112 4 109 4 128 MANGO 0 136 1 143 2 143 3 143 4 136 BANANA 0 5 1...
3
by: waynejr25 | last post by:
can anyone help me add a function that will count the occurance of each word in an input file. here's the code i have so far it counts the number of characters, words, and lines but i need the...
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
3
by: blunt | last post by:
right the program is nearly complete just a couple of little tweaks and i should have it. The purpose of this program is to write config files for colubrius wireless access points but it's falling...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.