Welcome to Dream.In.Code
Become a VB Expert!

Join 137,262 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,508 people online right now. Registration is fast and FREE... Join Now!




Counting number of Lines in text file

 
Reply to this topicStart new topic

Counting number of Lines in text file, Is there any way to count the number of lines in a text file?

demonzrulaz
3 Dec, 2006 - 03:00 PM
Post #1

New D.I.C Head
*

Joined: 30 Sep, 2006
Posts: 8


My Contributions
Is there any way to get the number of lines in a text file because the text file I need changes and I need to store every line into an array. I can't redimension the array if I don't know the number of lines in the file

CODE

Open "GRADES.TXT" For Input As #1 ' Opens file for input
    ReDim grades(1 To numGrades) As Integer ' Redims array to hold the grades
    Dim i As Integer ' dims counter variable
    For i = 1 To numGrades
        Input #1, grades(i)
    Next i
    Close #1 ' Closes file

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Counting Number Of Lines In Text File
3 Dec, 2006 - 04:45 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
http://www.vb-helper.com/howto_count_file_lines.html

Another method is to place the contents of the file into a string variable, and then count them number of new line characters.
User is offlineProfile CardPM
+Quote Post

A S H
RE: Counting Number Of Lines In Text File
8 Dec, 2006 - 09:23 PM
Post #3

New D.I.C Head
*

Joined: 8 Dec, 2006
Posts: 2


My Contributions
I think Amadeus gave u the answer
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:06PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month