thanks for that. i've checked the thread. but what i need is something like a function which will get the number of rows without looping through the lines because i'll be using it for my progress bar, to get the percentage of every bar increment during process looping
Tempstr = Space$(3000)
LF = Chr$(10)
Open InputFile For Binary As #1
Get #1, , Tempstr
RecordSize = InStr(1, Tempstr, LF)
Close #1
Open InputFile For Binary As #1
NumOfRecords = LOF(1) \ RecordSize
Close #1 Swi
To my knowledge, with a text file it is not possible to get the number of rows with actually reading the entire file because the file has no fixed format. In other words, you don't know how long any individual line is until you actually read that line.
It is possible however, if you know a typical, or average line length, to approximate the line count by using the LOF (length of file) function.
By dividing the results of the LOF by the typical line length (and I would add 1 more), you should have a reasonable estimate
of the number of lines. It won't always be exact, but it may very well suffice for a progress bar. Good Luck
-------------- As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
I agree with you here. For something like a progress bar this type of estimation is often required. In a case like this I might even read the 1st few lines of data to estimate the average length if I have no way to know what it'll be.
This can still make things way off, but so be it.
The Swi approach will work great for teeny files, but I deal with a lot of files in the multi-megabyte range, which is why I use progress bars anyhow. The processing takes awhile and I want to show the user progress feedback.
For teeny files??? My approach will return the size of a file up to 2 gig in size. This is because of VB's limiting LOF function. I work with flat files almost exclusively on a day to day basis and this is the way I determine how many records I am dealing with. My usual file size ranges from anywhere between 50 mb to over 2 gig. If you want to return the file size of a file larger than 2 gig you may want to look into the GetFileSize API. Swi
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.