Sri lanka web server - 170 CHAPTER 6 MAKING DECISIONS WITH CONDITIONAL

170 CHAPTER 6 MAKING DECISIONS WITH CONDITIONAL LOGIC Note Select Case statements can include an optional Case Else statement that executes only when none of the defined Case statements match up against the tested value. Note, the Select Case block accepts either Case Else or Else as the format of the optional Else clause. As you can see, a Select Case block is easier to read when compared to nested If Then blocks. In addition, Select Case blocks typically require less code statements to set up. The following example demonstrates how to set up a typical Select Case block. Select Case strCustomerName Case “Walmart” MsgBox(”Customer account number is 6765765765765.”) Return Case “Target” MsgBox(”Customer account number is 6769382576767.”) Return Case “Roses” MsgBox(”Customer account number is 1231435 456755.”) Return Case “Sears” MsgBox(”Customer account number is 98978562546573.”) Return Case Else MsgBox(”An account must be set up for this new customer.”) End Select In this example, a message is displayed depending on whether the value assigned to the strCustomerName variables match any of the values specified in the Case statements. However, if no match is found, the Case Else statement executes. Case statements are flexible. For example, you can set them up to check for a range of values using the To keyword, as the following shows. Select Case intNoOfPoints Case 1 To 1000 MsgBox(”Continue your training my young padewan learner.”) Return Case 1001 To 10000 MsgBox(”Your Jedi skills are indeed most impressive!”) Return Case 10001 To 1000000 MsgBox(”Congratulations Master Jedi, you are truly strong with the force.”) Return End Select
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply