Results 1 to 3 of 3

Thread: Retrieving the number of records from a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Question

    The FileLen procedure that was explained on the site returns the size of a file in bytes. However, this is quite useless, especially if it is a random file with records. To get the records I've done different crazy stuff such as dividing the FileLen by the size of a default record and then rounding it to the nearest number...it works but there has to be a smarter way of doing it. (for example in Turbo Pascal, filesize(somefile) returns the number of records in a file, not its size in bytes). Any such commands in VB??

  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    I would have thought that short of actually saving the number of records in a file into a seprate file that the method you mentioned is the best (from my experience anyway) and seeing as your using RANDOM files, all the record lengths are the same therefore it works, unless your using BINARY files inwhich case you will have problems

    I would just go:

    Maxrecords=FileLen(Thisfile)/Len(thisrecord)
    taking it for granted that the file exists.

    DocZaf
    {;->

  3. #3
    Guest
    FileNumber = FreeFile()
    Open "C:\TestFile.txt" For Random As FileNumber Len = Len(rec)
    Do Until EOF(FileNumber)
    i = i + 1
    Get FileNumber, i, rec
    Loop

    'rec is the UDT variable
    'var i will return the number of records
    'that are in the file

    the problem i have is when i delete a record
    the length of the UDT still remains in the file
    which therefore, in my case, i will return an
    incorrect number.

    if anyone knows a way to remove the dead space from
    a deleted record in a random access file let me know

    hope this helps you out..

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