function to find number of lines in .txt file
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
the Function would return the value 4.
thanks in advance,
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
LineCount = I
Private Sub Command1_Click()
MsgBox LineCount(Environ$("WinDir") & "\Win.INI")
please note if u use : option explicit , u must define all variables e.g. ( Dim I as Long )
that worked great!
Last Post: 12-13-2006, 02:49 PM
By Marcos in forum VB Classic
Last Post: 01-25-2006, 11:18 AM
By K. Soe in forum VB Classic
Last Post: 03-08-2003, 06:25 PM
By Michael Shutt in forum VB Classic
Last Post: 04-05-2001, 02:25 AM
By Dan in forum VB Classic
Last Post: 03-17-2000, 05:14 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center