[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




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 

bulletDownload source
bulletDownload  executable

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.


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.