Range check

Tags
Summary

Check whether a number is between two other numbers.

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

Situation

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

Needs

Minimum, maximum, and a value to check.

Provides

A validated number, or an error.

Action

An example:

  • sMonth = InputBox("Birthday month (1-12)?")
  • If sMonth >= 1 And sMonth <= 12 Then
  •     tMessage = "Thanks for the month"
  • Else
  •     tMessage = "Sorry, " & sMonth & " isn't a valid month."
  • End If
  • MsgBox tMessage