This planning will take some time, but, it will save time in the long run. The plan will also become part of the documentation of the program.
For now, you can plan what your event handlers will do and what variables you will use. Once you have the plan, coding will be simple, and you will cut down on logical errors.
You should state what each event handler will do. (This may be only one thing or it may be a complex series of steps, a complex algorithm).
You should also state the characteristics of each variable you plan to use: purpose, name, data type, initial value and scope. If a variable can be local, it should be. If possible, make all variables local. Doing so will make your program easier to read and there will be less chance of inadvertent logical errors.
For example, here is the plan I made before writing a payroll program:
Event handlers:
Event: The user clicks on the Calculate Pay button Action(s) to take: Compute and display gross pay, tax and net pay Event: The user clicks on the Stop button Action(s) to take: Close the program Event: The hours worked textbox gets focus Action(s) to take: Clear the gross pay, tax and net pay Event: The hourly rate textbox gets focus Action(s) to take: Clear the gross pay, tax and net payVariables:
Name: sngHours Data type: single precision Purpose: the number of hours worked Initial value: 0 Scope: local Name: sngRate Data type: single precision Purpose: the rate of pay Initial value: 0 Scope: local Name: sngGross Data type: single precision Purpose: the number of hours worked Initial value: 0 Scope: local Name: sngTax Data type: single precision Purpose: the amount of tax Initial value: 0 Scope: local Name: sngNet Data type: single precision Purpose: the number of hours worked Initial value: 0 Scope: local Name: sngTotal Data type: single precision Purpose: the sum of everyone's gross pay Initial value: 0 Scope: global
In an earlier note we spoke of five steps in developing a program. We have now added a new step, planning the internal structure of the program: