Results 1 to 7 of 7

Thread: How do you count the amount of lines in a txt file?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    NJ
    Posts
    49

    How do you count the amount of lines in a txt file?

    look at the subject

  2. #2
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155
    Code:
    Open "myfile.csv" For Input As #1
    
    	While Not EOF(1)
    
    		Line Input #1, foo$
    		Lines = Lines + 1
    
    	Wend
    
    Close #1
    
    MsgBox "Your file had " & Lines & " lines."

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi there NPerezVB, a sample for u

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4.  
    5. Private Const EM_GETLINECOUNT = &HBA
    6.  
    7. Private Sub Text1_Change()
    8.     Dim lineCount As Long
    9.     On Local Error Resume Next
    10.  
    11.     lineCount = SendMessageLong(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
    12.     Label1 = Format$(lineCount, "##,###")
    13. End Sub
    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    uh... could swear it said text box
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     MsgBox GetNumLines("C:\TEST.TXT")
    5. End Sub
    6.  
    7. Private Function GetNumLines(sFileName) As Integer
    8.         Open sFileName For Binary As #1
    9.         GetNumLines = UBound(Split(Input(LOF(1), 1), vbCrLf)) + 1
    10.         Close #1
    11. End Function
    -= a peet post =-

  6. #6
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Actually, Peet

    Do you think you can help us with this problem:

    http://www.vbforums.com/showthread.p...hreadid=146098

    We are considering counting lines in an RTF box.

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    the answer is the same for RTBoxes as Text boxes HaxSoft, just change the Text1 to RichTextBox1
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width