Domino Code Fragment

Code Name*
Conditional Branching: The Select Case Statement
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.138.141.202
Description*
The Select Case statement allows a program to conditionally execute statements based on any number of conditions.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Select Case comes in handy when a variable could have one of several different several values, and you want to execute different code based on any one of those values. Select Case always has a variable name after it. It takes the value in the variable and compares it to each case. If a match is found, the code in the matching case is executed. The Case Else statement is a catch-all statement. Think of Case Else as being the code to be executed if none of the other conditions met. Case Else is optional.

Syntax
Select Case variable
Case 1 condition
statements
Case 2 condition
statements
Case 3 condition
statements
:
:
Case Else
statements
End Select

The example below asks for your age. It then checks to see if the number is numeric. If it is numeric, the Select Case statement checks to see if the age entered is 10 or 20 or any other number. Depending on the value, different code is executed. If the number entered was not numeric, the message `You didn't enter a number!' is displayed. Notice the Select Case is inside an If loop. You will find that nesting one loop inside another can give you flexibility that you would not otherwise have.

Click here to view the example.

Dim X As Variant 'Declare X as type Variant
X = Inputbox("What is your age?")
'Ask for the user's age
If Isnumeric( X) Then
'If X is numeric, execute the following code
Select Case X
'Check the value of X to see if it matches any of
'the cases below
Case 10
'In the case that X is equal to 10, execute the
'following code
Messagebox "You are 10 years old."
'Display a message stating the user is 10 years old
Case 20
'In the case that X is equal to 20, execute the
'following code
Messagebox "You are 20 years old."
'Display a message stating the user is 20 years old
Case Else
'If none of the above cases are true, execute the
'following code
Messagebox "You are neither 10 nor 20 years old."
'Display a message stating the user is
'neither 10 nor 20 years old.
End Select
'End of SELECT CASE statement
Else
'From the IF statement: If X is not numeric
Messagebox "You didn't enter a number!"
'Display a message stating the user did not enter a
'numeric age
End If
'End of IF statement