Examples: Exit statement

' The user is asked to enter a 5-character string. If the 
' length of the entry is not 5, the result of Exit Function is 
' to return the empty string and issue a message telling you
' the entry is invalid.

Function AssignCode As String
   Dim code As String
   code$ = InputBox("Enter a 5-character code")
   If Len(code$) <> 5 Then Exit Function
   AssignCode = code$               ' It is a valid code.
End Function
If AssignCode() <> "" Then
   MessageBox "You entered a valid code."
Else
   MessageBox "The code you entered is not valid."
End If