Access VBA Counting Loops

I am having a bit of trouble figuring out how to count the number of loops that will occur in a bit of programing. There must be a short cut of some sort that you can use a calculator to determine the count. I can step through the code using the F8 key and watch the code count the loops but I have trouble determining the count prior to running the code itself.

Below are examples:

'Do ... Loop Until - evaluates at bottom - continues until the test is true

Private Sub cmdForNext_Click()
  'declare variables
  Dim intNumber As Integer, intCounter As Integer, strText As String
  'assing values
  intNumber = Val(Me.txtNumber)
  strText = Me.txtText
  'set up loop
  Dim intI As Integer
  For intI = intNumber To 10 Step 2
  'concatenate strText
  strText = strText & " * "
  'count loops
  intCounter = intCounter + 1
  'the next reserved word increments the control variable, in this case intI
  Next intI
   
    Me.lblResult.Caption = "The loop ran " & intCounter & " times." & vbCrLf & "The text concatnated to: " & strText & vbCrLf & "The value of intI is: " & intI
   
   

End Sub


Another example:


'evaluates at top

Private Sub cmdDoUntil_Click()
  'declare variables
  Dim sngNumber As Single, intCounter As Integer, strText As String
  'assing values
  sngNumber = Val(Me.txtNumber)
  strText = Me.txtText
  'set up loop
  Do Until sngNumber = 4
  'increment sngNumber
  sngNumber = sngNumber + 1
  'count loops
  intCounter = intCounter + 1
  'concatenate strText
  strText = strText & " * "
 
  Loop
    Me.lblResult.Caption = "The loop ran " & intCounter & " times." & vbCrLf & "The number changed to: " & sngNumber & vbCrLf & "The text concatneated to: " & strText
   
   

End Sub


Final example:


'evaluates at top

Private Sub cmdDoWhile_Click()
'declare variables
Dim sngNumber As Single, intCounter As Integer, strText As String
'assign values
sngNumber = Val(Me.txtNumber)
strText = Me.txtText
'set up loop
Do While sngNumber <= 5
  'increment sngNumber
  sngNumber = sngNumber + 1
  'count loops
  intCounter = intCounter + 1
  'concatenate strText
  strText = strText & " * "
  Loop
 
 
 
  Me.lblResult.Caption = "The loop ran " & intCounter & " times." & vbCrLf & "The number changed to: " & sngNumber & vbCrLf & "The text concatenated to: " & strText


End Sub

I have provided the file containing the above code.
240JRC-TutC2.accdb
James CoatsComputer Info. Sys. StudentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
What is your problem?

The loop count will vary - and will adopt - to the input parameter (txtNumber).

/gustav
0
Rey Obrero (Capricorn1)Commented:
first, what items are you going to process inside your loop?
if you are going to process recordsets, you can do this

dim recCount as integer, j as integer
if not rs.eof then
rs.movelast
recCount=rs.recordcount
end if
rs.movefirst
for j=1 to reccount
'codes here
rs.movenext
next j
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James CoatsComputer Info. Sys. StudentAuthor Commented:
Thank you that answered my question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.