473,800 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\MyTextF ile" 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 7388
"Peter" <pe***@mclinn.c om> 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:\MyTextF ile" 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 CountTextFileLi nes
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.Ope n, _
IO.FileAccess.R ead, IO.FileShare.Re ad _
)

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*******@free net.de> wrote in message
news:uE******** ******@TK2MSFTN GP09.phx.gbl...
"Peter" <pe***@mclinn.c om> 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:\MyTextF ile" 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 CountTextFileLi nes
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.Ope n, _
IO.FileAccess.R ead, IO.FileShare.Re ad _
)

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****@blowgoa ts.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.MyFunctio n("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******** ******@TK2MSFTN GP09.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
3907
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
61418
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: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
4
1680
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 group of objects and their memebers or a few lines of text? and 2) Is there any way to automate object construction? I'm thinking that I can create a vector or something similar to handle the number of people, is there a way for me to write a...
1
3158
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> #define MB 1048576
28
1834
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 file and remove all the blank ones. One solution I tried is to open the file and use readlines(), then copy that list into another variable, but this doesn't seem very efficient to have two variables representing the file. Perhaps there's also...
8
3746
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 12 1 15 2 13 3 6 3 9 I need to read the above file and have the following information in the output file In APPLE 0 occurs 1 time, 1 occurs 3 times, 2 occurs 1 time, 3 occurs 3 times
3
2712
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 occurance of each word. #include <fstream> #include <iostream> #include <string> #include <cstdlib> using namespace std;
16
4441
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 : size_t linecnt(char *filenm); * Author : jhlicfoocbar@gmail.com, remove foobar for email * Date : 2008.4.12 * Description: C source code line count. No comments & no space lines
3
5092
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 over in this section of code: while(line!=32){ fgets(c, 1, sourceFile); strncpy (compare,c,1); if (compare=='\n'){ line++; } }
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.