Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

CHAPTER 4 CONDITIONS > SELECT CASE STRUCTURES

SELECT CASE STRUCTURES

The Select Case structure is another tool for VBA programmers to use to build conditions. Specifically, the Select Case structure evaluates an expression only once. It’s useful for comparing a single expression to multiple values.

Select Case sDay
    Case “Monday”
       Me.lblDay.Caption = “Weekday”
    Case “Tuesday”
       Me.lblDay.Caption = “Weekday”
    Case “Wednesday”
       Me.lblDay.Caption = “Weekday”
    Case “Thursday”
       Me.lblDay.Caption = “Weekday”
    Case “Friday”
       Me.lblDay.Caption = “Weekday”
    Case Else
       Me.lblDay.Caption = “Weekend!”
End Select

In this case (excuse the pun) the Select Case structure evaluates a string-based variable and uses five Case statements to define possible expression values. The Case Else statement catches a value in the top expression that is not defined in a Case statement.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial