If-Then-Else, VBA statement.
Syntax
Select Case test_expression
Case condition_1
result_1
Case condition_2
result_2
...
Case condition_n
result_n
[ Case Else
result_else ]
End Select
Key
test_expression An expression returning a string or numeric value.
This value will be compared to the list of conditions.
condition_n Conditions are evaluated in the order listed.
Once a condition is found to be true, the corresponding code
will be executed and no further conditions will be evaluated.
result_n The code to be executed when a condition is met.
Comparison operators: Less than <, Less than or equal to <=, Greater than >, Greater than or equal to >=, Not equal <>, Equal =
Range comparison can also be done: 1 To 10 or 500 To 600
or the comparison can be a comma separated list of items: 2,4,6,8,10 or "Jan", "Feb", "Mar"
Dim intVoltage as Integer
Dim strDescription as String
intVoltage = Me.txtVoltage
Select Case intVoltage
Case 110
strDescription = "Domestic"
Case 220,240
strDescription = "European"
Case 600
strDescription = "Industrial"
Case Else
strDescription = "Unknown"
End Select
MsgBox strDescription
A function to return a number with an ordinal suffix, like 2nd:
Function GetSuffix (intDay As Integer) As String
Dim intDigit As Integer
If intDay >=11 and intDay <=19 Then
GetSuffix = "th"
Else
intDigit = intDay Mod 10
Select Case intDigit
Case 1
GetSuffix = "st"
Case 2
GetSuffix = "nd"
Case 3
GetSuffix = "rd"
Case Else
GetSuffix = "th"
End Select
End If
End Function
“You see things; and you say 'Why?' But I dream things that never were; and I say 'why not?'” ~ George Bernard Shaw
Nz - Detect a NULL value or Zero Length string.
If-Then-Else