Pattern catalog

Patterns are common ways of doing things, like recipes. People have patterns for solving equations, making web pages, wrapping gifts, all sorts of things. Part of learning a skill is learning the patterns that help you be more effective.

Here are patterns on this website. This list can help you find the patterns you need to do a task.

Name Tags Situation Pattern summary, needs, provides Where referenced
Range check Validation, If

You have a number that might be too small, or too high. You want to check it, to make sure it's OK.

Check whether a number is between two other numbers.

Warning: "range" has two meanings. This pattern is not about Range objects.

Needs: Minimum, maximum, and a value to check.

Provides: A validated number, or an error.

Logical operators, Basic validation: numeric, Validating during CSV input, CSV data into arrays
Read a CSV data file CSV, Files, Arrays

You have a CSV data file that you want to process.

Use a loop to read CSV data into arrays, one record at a time.

Needs: A CSV data file.

Provides: Arrays with data from the CSV file.

CSV data into arrays
Read until end of file Files, Loop

You have a file with data you want to process.

Open a file, read until the end of the file is reached, then close the file.

Needs: A file.

Provides: Data in memory, extracted from the file.


You need to do a simple computation.

A simple sequence of statements.

Needs: Some variables whose values need to be changed.

Provides: Variables with changed values.

Validation (better) Validation

You have several pieces of data to check. You want to show all the errors at once.

Wrap a bunch of individual checks inside the flag pattern.

Needs: Several pieces of data you don't trust.

Provides: Checked data you can work with.

Better validation
Validation (numeric, basic) Validation

You have some data that's supposed to be numeric. Could be from a cell, a file, a dialog box, wherevs. You want to check the data.

Test that data is numeric. Add range checks and other tests, as needed.

Needs: A data value.

Provides: Number that's valid, or an error message.

CSV data into arrays
Validation (string, basic) Validation

You have some string data you don't trust. Could be from a cell, a file, a dialog box, wherevs. You want to check the data.

Normalize, then test with If(s).

Needs: Some string data.

Provides: String data that's valid, or an error message.

Basic validation: strings
Variable increase/decrease

You are accumulating a value, like a total, or count.

An assignment statement, like sTotal = sTotal + sSales. Adds to a variable, then puts the result back in the variable.

Needs: A variable to be increased/decreased, and a value to add or subtract.

Provides: A variable that has been increased/decreased.

Numeric expressions