?
Solved

I need a do while loop to count

Posted on 2003-03-12
5
Medium Priority
?
169 Views
Last Modified: 2010-05-01
To count the number of records in a .dat(txt) file, then display in a lblXXX.Caption.

How can I do it to where I don't know how many records there are but at the same time end when it has counted them all, displaying the number of records (lines) i.e. end of file.
0
Comment
Question by:GlobalFax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Accepted Solution

by:
jlbonano earned 800 total points
ID: 8125106
Try this.  You don't need to do the input for the count but if you need the data then you can.

Dim i       As Integer
Dim iFile   As Integer

i = 0
iFile = FreeFile

Open strPingData For Input As iFile
Do While Not EOF(iFile)
    Input #iFile, strLine
    '-- Do whatever with strLine
    i = i + 1
Loop

Me.lblALabel.Caption = i

Close #iFile
0
 
LVL 2

Expert Comment

by:Sweat
ID: 8125139
GlobalFax,

You didn't mention what type of recordset you were using. How about this:

' Declare it...
Dim rs as RecordSet
dim vCount

' Populate the recordset using SQL, ADO, DAO it doesn't matter

Do
   vCount = vCount + 1
   lblXXX.Caption = vCount

   rs.MoveNext
Loop Until rs.EOF = True

But.  If you were using something structured like ADO or DAO you have the count of records available without needing to count.  rs.RecordCount is a property that holds the number of rows in the record set. (Be careful with DAO, you need to move to the end of the rs before that property is accurate).

If you are just reading a text file and counting lines, you would open the text file: Open "c:\me.txt" For Input As #1.

Then you'd read each line till the file is done:

Dim sLine
Dim vCount

Do
   vCount = vCount + 1
   lblXXX.Caption = vCount

   Line Input #1, sLine
Loop Until EOF(1) = True

Does this help?

Sweat

0
 
LVL 39

Expert Comment

by:appari
ID: 8125148
try something like this

dim FNo as integer, LineCnt as integer
FNo = freefile

open datfilename.dat for input as #FNo
LineCnt=0
while not EOF(FNo)
  line input #FNo, strData
  LineCnt = LineCnt+1
wend

close #FNo

lblXXX.Caption=LineCnt
0
 
LVL 39

Expert Comment

by:appari
ID: 8125159
jlbonano: almost same as yours:), i was late in posting as i had to attend a phone
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8125165
Thanks, I did the data abd replaced the strPingData with the file path.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question