Input validation loop

Situation: 

You want to keep asking the user for input until it's valid.

Actions: 

Use input validation with a flag controlled loop. See the Explanation in this code for an example.

Explanation: 

Flowchart

  1. Dim userInput As String
  2. Dim numericVar as Single
  3. Dim errorFlag As Boolean
  4. errorFlag = False
  5. Do
  6.     userInput = InputBox(prompt)
  7.     If userInput = "" Then
  8.         errorFlag = True
  9.     ElseIf Not IsNumeric(userInput) Then
  10.         errorFlag = True
  11.     ElseIf Val(userInput) < 0 Then
  12.         errorFlag = True
  13.     End If
  14.     If errorFlag Then
  15.         MsgBox "Please enter a number, zero or more."
  16.     End If
  17. Loop While errorFlag
  18. numericVar = Val(userInput)