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

Event Driven Programming



                          Do loops are commonly used to ensure that a proper response is received from the InputBox
                          function.

                                        2: The following program requires the user to enter a number from 1-3. The
                                           Do loop repeats the request until the user gives a proper response.



















                                        Object             Property              Setting
                                  frmMovie           Text               6-1-2
                                  btnDisplay         Text               Display a Movie Quotation
                                  txtQuotation       ReadOnly           True

                          Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
                            Dim response As Integer, quotation As String = “”
                            response = CInt(InputBox(“Enter a number from 1 to 3.”))
                            Do While (response < 1) Or (response > 3)
                              response = CInt(InputBox(“Enter a number from 1 to 3.”))
                            Loop
                            Select Case response
                              Case 1
                                quotation = “Plastics.”
                              Case 2
                                quotation = “Pardip.”

                              Case 3
                                quotation = “That’s all folks.”
                            End Select
                            txtQuotation.Text = quotation
                          End Sub
                          [Run, and click the button.]








                          136                    LOVELY PROFESSIONAL UNIVERSITY
   137   138   139   140   141   142   143   144   145   146   147