Page 160 - Open Soource Technologies 304.indd
P. 160

Event Driven Programming



                          Different items appearing in the same list must be separated by commas. Each action consists
                          of one or more statements. After the selector is evaluated, Visual Basic looks for the first value-
                          list item including the value of the selector and carries out its associated action. (If the value of
                          the selector appears in two different value lists, only the action associated with the first value
                          list will be carried out.) If the value of the selector does not appear in any of the value lists and
                          there is no Case Else clause, execution of the program will continue with the statement following
                          the Select Case block.

                                        3: The following program uses several different types of value lists. With the
                                           response shown, the second action was Selected.




















                              Object               Property              Setting
                              frmRhyme             Text                  One, Two, Buckle My Shoe
                              lblEnterNum          Text                  Enter a number from 1 to 10:

                              txtNumber
                              btnInterpret         Text                  Interpret Number
                              txtPhrase            ReadOnly              True

                          Private Sub btnInterpret_Click(...) Handles btnInterpret.Click
                            ‘One, Two, Buckle My Shoe
                            Dim x As Integer = 2, y As Integer = 3
                            Dim num As Integer
                            num = CInt(txtNumber.Text)
                            Select Case num
                               Case y - x, x
                                txtPhrase.Text = “Buckle my shoe.”
                               Case  Is  <=  4
                                txtPhrase.Text = “Shut the door.”
                               Case x + y To x * y
                                txtPhrase.Text = “Pick up sticks.”




                          154                    LOVELY PROFESSIONAL UNIVERSITY
   155   156   157   158   159   160   161   162   163   164   165