Math Facts Form Needs Time Limit

Richard McCabe

Registered User.
Local time
Today, 00:52
Joined
Mar 6, 2012
Messages
19
I have a multitude of grandchildren some of which are ready to learn math facts. At this age they would rather play on a computer than do flash cards so I'll give them a computer to play with.

I have the form working fairly well, but need to add time limits of various lengths to build speed. I have timer written to add various times to solve the fact.

When the timer is running, I can find no way to enter the correct answer, and when the time expires, the program counts the problem wrong and advances to the next fact.

What an I missing?
 
Rather that use the timer event, you could use the Time() function to capture the current time when the user moved to the current record and then again to capture the time when the task is completed. You can then use the DateDiff() function to calculate and display the time taken to complete the task.
 
If you're using a do while loop, you can add the command DoEvents inside the loop, which tells VBA to pay attention to other stuff rather than just watching the program go round and round.
 
Math Facts Form Needs Time Limit-I

Many thanks to widmerpool for comment suggesting DoEvents to allow answer entries while timer is running. This works great!!!!!!

A second problem is that I neeed to evaluate three criteria to determine if the timing loop should initiate or continue.

Criteria #1 is that the total time has not been used.
Criteria #2 is that the table containing the facts has not reached the end of the file.
Criteria #3 is that the timing function has not been disabled by a command button. Sometimes we don't want to time!"

Can all three criteria be done in one Do While / Loop?
Richard McCabe
 
Sure. You can have separate "IF...THEN" tests, or you can combine them using ELSE. You'll probably want to keep them separate, as it's easier to keep track of the various conditions that way. And the disable-timing test could go outside the loop, as I presume you wouldn't need to retest the condition several times a second!

Here's an example (from Excel, but the principle's the same):
Code:
Private Sub ToggleButton2_Click()
  [COLOR="Red"]Dim counter As Integer
  If Range("b2").Value = False Then counter = 0 Else counter = 1[/COLOR]
  [COLOR="Olive"]Do Until Range("a2").Value = False[/COLOR]
    DoEvents
    Calculate
    [COLOR="RoyalBlue"]Range("g2") = Range("g2").Value + counter
    If Range("g2").Value = 1000 Then
      Exit Do
    End If[/COLOR]
  [COLOR="Olive"]Loop[/COLOR]
End Sub

So the red section decides whether the counter runs or not, the "UNTIL" in the green section keeps the loop going as long as the "stop" button isn't clicked, and the within-loop "if...then" test in the blue section checks the counter and exits the loop once it hits the limit.

You can use any or all of these, and you can have several "if...then" tests within a single loop.

If you have nested loops, the "exit do" command only springs you up one level - you leave the inner loop, but you're still in the outer loop.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom