-
function to find number of lines in .txt file
hello,
I have a file C:\test\test.txt that I'd like to, using a Function where you pass in the Directory and Filename that you want to utilize, in this case C:\test and test.txt, calculate the number of lines in the text file and return that value from the Function.
Could someone share with me the code that would do this?
ex. if test.txt looked like
lskdjflskjf
lksdflksdj
slkdjf
lksjdf
the Function would return the value 4.
thanks in advance,
david
-
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Hello dgr7 ,
This code can help you :
code for counting lines of win.ini file :
Private Function LineCount(FileName As String) As Long
Open FileName For Input As #1
Do While Not EOF(1)
I = I + 1
Line Input #1, D
Loop
Close #1
LineCount = I
End Function
Private Sub Command1_Click()
MsgBox LineCount(Environ$("WinDir") & "\Win.INI")
End Sub
please note if u use : option explicit , u must define all variables e.g. ( Dim I as Long )
-
amrelsaqqa,
thank you!
that worked great!
Similar Threads
-
Replies: 18
Last Post: 12-13-2006, 02:49 PM
-
By Marcos in forum VB Classic
Replies: 3
Last Post: 01-25-2006, 11:18 AM
-
By K. Soe in forum VB Classic
Replies: 8
Last Post: 03-08-2003, 06:25 PM
-
By Michael Shutt in forum VB Classic
Replies: 6
Last Post: 04-05-2001, 02:25 AM
-
By Dan in forum VB Classic
Replies: 0
Last Post: 03-17-2000, 05:14 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks