Results 1 to 4 of 4

Thread: small bit of code to count the records in a txt or .dat file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300
    Hi I need to check that the number of lines produced in a .dat file is the same as the number of records in a access db table.

    I just want to open the .dat file and count the lines. I tried this but it got stuck in a loop. Why ?
    what did I do wrong.


    Private Sub Command1_Click()
    Dim filenum As Integer
    Dim num As Long

    filenum = FreeFile
    num = 0
    Open "c:\store\imascons.dat" For Input As #filenum
    Do Until EOF(filenum)
    num = num + 1
    MsgBox num
    Loop
    Close filenum
    MsgBox num



    End Sub


    This didnt work , anyone ?

    Thx locutus
    Resistance is futile

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Looks like you need to read the file in order to get the pointer to move through it. Otherwise it will just count forever.

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Cool Don't know...

    Try this....

    Code:
    filenum = FreeFile
    num = 0 
    strVar = ""
    Open "c:\store\imascons.dat" For Input As #filenum 
    Do While Not EOF(filenum)
    LineInput #1,strVar 
    num = num + 1 
    MsgBox num 
    Loop 
    Close filenum 
    MsgBox num
    Just a shot.


    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Lively Member Ianf's Avatar
    Join Date
    Mar 2000
    Location
    Leigh, Lancashire, UK
    Posts
    96

    Cool Count Lines

    This will work definatly

    Dim FileNumber As Integer
    Dim FilePath As String
    Dim LineCount As Integer
    Dim Data As String

    ' Initialisation
    LineCount = 0
    FilePath = "C:\Filename"
    FileNumber = FreeFile

    ' Open the file
    Open FilePath For Input Access Read As #FileNumber

    ' Parse the file
    Do Until EOF(FileNumber)

    Line Input #FileNumber, Data
    LineCount = LineCount + 1

    Loop

    Close #FileNumber
    Ian Frawley
    Software Engineer
    E-mail [email protected]

    BEING IN THERAPY
    And yet, having therapy is very much like making love to a beautiful woman. You... get on the couch, string 'em along with some half-lies and evasions, probe some deep dark holes, and then hand over all your money.

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