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

Unit 6: VB Control Structure






















                    Object              Property          Setting
                    frmMillionaire      Text              6% Interest

                    LblAmount           Text              Amount Deposited:
                    TxtAmount
                    btnCalculate        Text              Calculate Years to Become a Millionaire
                    TxtWhen             ReadOnly          True

               Private Sub btnYears_Click(...) Handles btnYears.Click
                 ‘Compute years required to become a millionaire
                 Dim balance AsDouble, numYears As Integer
                 balance = CDbl(txtAmount.Text)
                 DoWhile balance < 1000000
                   balance += 0.06 * balance
                   numYears += 1
                 Loop
                 txtWhen.Text = “In “ & numYears & _
                               “ years you will have a million dollars.”
               End Sub
               [Run, type 100000 into the text box, and press the button.]






                                                        100000





                                      In 40 years you will have a millon dollars





                                      LOVELY PROFESSIONAL UNIVERSITY                        139
   140   141   142   143   144   145   146   147   148   149   150