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

Unit 6: VB Control Structure




                              Object        Property      Setting
                              frmFirst      Text          Find Earlier College

                              btnFirst      Text          Get Data  on First College
                              btnSecond     Text          Get Data on Second College
                              btnOlder      Text          Display Data  on Older College
                              txtResult     ReadOnly      True
                              College

                  Dim name As String
                 Dim state As String
                 Dim yearFounded As Integer

               End Structure
               Dim college1, college2, collegeOlder As College
               Private Sub btnFirst_Click(...) Handles btnFirst.Click
                 Dim prompt As String
                 college1.name = InputBox(“Enter name of first college.”, “Name”)
                 college1.state = InputBox(“Enter state of first college.”, “State”)
                 prompt = “Enter the year the first college was founded.”
                 college1.yearFounded = CInt(InputBox(prompt, “Year”))
               End Sub
               Private Sub btnSecond_Click(...) Handles btnSecond.Click
                 Dim prompt As String
                 college2.name = InputBox(“Enter name of second college.”, “Name”)
                 college2.state = InputBox(“Enter state of second college.”, “State”)
                 prompt = “Enter the year the second college was founded.”
                 college2.yearFounded = CInt(InputBox(prompt, “Year”))
               End Sub
               Private Sub btnOlder_Click(...) Handles btnOlder.Click
                 If (college1.yearFounded < college2.yearFounded) Then
                   collegeOlder = college1
                 Else
                   collegeOlder = college2
                 End If
                 txtResult.Text = collegeOlder.name & “ was founded in “ & _
                    collegeOlder.state & “ in “ & collegeOlder.yearFounded & “.”
               End Sub
                [Run, click the first button, and respond to the input boxes with Delhi University, , 1746. Click
               the second button; respond to the input boxes with NIPS University, Connecticut, 1701. Finally,
               click the third button.]




                                      LOVELY PROFESSIONAL UNIVERSITY                        125
   126   127   128   129   130   131   132   133   134   135   136