Flag

Keywords: 
Situation: 

You want to keep track of whether something happened. For example, whether one of several input errors happened.

Actions: 

Use a variable as a flag. Write code that initializes it, sets it if some condition occurs, then checks it. See this pattern's Explanation for an example.

Explanation: 

An example.

  1. Dim badData As Boolean
  2. 'Set a flag to show data isn't bad.
  3. badData = False
  4. If [some error condition] Then
  5.     badData = True
  6. ElseIf [some error condition] Then
  7.     badData = True
  8. ElseIf [some error condition] Then
  9.     badData = True
  10. End If
  11. 'Any of tests show bad data?
  12. If badData Then
  13.     'Respond to error.
  14. Else
  15.     'Process data
  16. End If