Problem Description
In this arithmetic drill program, the user answers
as many randomly generated problems as possible in 60 seconds. The operation (addition, subtraction, multiplication,
division or a random selection) as well as the maximum and minimum
values for forming the problems are set by the user.
Background & Techniques
Here's a fun little arithmetic drill program
that I converted from a JavaScript version that resides on
this page over at Argonne National Laboratories. The
program was written by David Baurac in 1998. I sent an email
asking for permission to post this Delphi version, but received no
answer -- so I decided to post it anyway. . Hope I don't
wind up in jail.
I modified it slightly by removing the
buttons (the kids complained that switching from entering numbers to
clicking the mouse on the "Check Answer" button slowed them
down). So my version uses the G key for Go, the S
key for Stop and the Enter key for "Check Answer".
The program is pretty straightforward with a
couple of cracks that needed to be plugged: Grandson
Jeff answered 140 problems correctly before I stopped allowing maximum
and minimum to be the same value. I adopted the same
strategy as the original author for handling minimum range value greater
than maximum value, just reverse the entries.
Non-programmers can jump to
the bottom of the page to download the executable version of
Arithmattack.
Notes for Programmers
Just a couple of notes that may be of
interest.
The program sets the Keypreview property
of TForm to true so that the form's OnKeyPress exit sees
all key presses first. This lets us recognize the G (Go) key
particularly, even if the focus is on one of the edit boxes.
I used an OnExit
event from the range edit fields to make sure that high of range was
greater than low. It made sense to me that when the user
pressed G or clicked on the "Press G" message, the exit
procedure would process before the "OnClick"
event". Not true. OnExit occurs when
the focus changes, which didn't occur until the end of the MakeProblem
procedure when I set the focus to the answer edit box - too late for that
first problem. The fix was simple - I moved the AnsEdt.Setfocus
statement from the end to the beginning of the MakeProblem
procedure.
Running/Exploring the Program
Suggestions for Further Explorations
One of these days, I'm going to take the time to figure out the
easiest way to scale pages for multiple screen resolutions. This
program maximizes the form to full screen but the content stays in the
original 640X480 boundaries. I have a feeling that there is no
simple way - there are user components that do it. Maybe Delphi 6
helped - guess I'll go check. |