Patterns
A pattern is a common way of doing things. Here are the patterns on this site.
Pattern | Keywords | Situation | Actions | Referenced in |
---|---|---|---|---|
Input validation loop | Loop, Input, Input validation |
You want to keep asking the user for input until it's valid. |
Use input validation with a flag controlled loop. See the Explanation in this code for an example. |
|
Input-processing-output |
Data needs to be transformed into other data, without user interaction after input. |
Use abstraction to define each of the three parts, and the way they communicate. Abstraction means that you:
|
Chunks and patterns Patterns nest User input and flags Finding the end |
|
Interfaces, properties, and events |
You want to write a GUI program. One with command buttons, textboxes, and other graphical controls. |
|
||
Loop | For-Next, Do-Loop | |||
Loop across array |
For next. Loop forwards. Loop backwards. Step – 1. |
|||
Loop across array and accumulate | ||||
Loop and accumulator | For-Next | |||
Main program calls subs | Subroutine |
You have a relatively complex program. It's too big to think about all at once. |
Break the program into subs. The main program coordinates passing data between the subs. |
Better thunking |
Naming controls | ||||
Nested loop | For-Next | |||
Output to a file - known amount of data | Output, File |
Your program needs to output data. You know exactly how many elements, and what type each one is. |
Use the File open, process, close pattern to open and close the file. Processing uses the |
Patterns nest |
Output to a Web page | ||||
Output to screen - known amount of data | Output |
Your program needs to output data to the user. You know exactly how many elements you want to display, and what type they are. The tip program is an example. |
Use |
Patterns nest |
Output to worksheet cells - known amount of data | Output, Worksheet |
Your program needs to output data to the user. You know exactly how many elements you want to display, and what type they are. The tip program is an example. |
Choose a few cells on a worksheet. Output data to those cells with the |
Patterns nest |
Reading file data into an array | ||||
Showing all error messages | Error | |||
Switch |