MACRO LIBRARY

Switch example

Free public access. No account or subscription required.

Files

Switch example

Code

Module: mMain

'Demonstrates how to use the Switch statement, which is a faster way to evaluate several
'   conditional statements quickly compared to using If - ElseIf or Select Case.
    
'Switch will evaluate the expressions left to right and return the value assocated with
'   the first true expression. If no true expressions are present then Null is returned.
    
Sub main()
    Dim retVal As String
    retVal = Switch(Timer < 43200, "Before noon", Timer = 43200, "Noon", Timer > 43200, "After noon")
    
    If IsNull(retVal) Then MsgBox "No true expressions found" Else MsgBox retVal
End Sub