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

Unit 8: Understanding Function and Procedure


                 ‘having sides of lengths a and b
                 Return Math.Sqrt(a ^ 2 + b ^ 2)
               End function
               function FutureValue(ByVal p As Double, ByVal r As Double, _
                           ByVal c As Double, ByVal n As Double) As Double
                 ‘Find the future value of a bank savings account
                 ‘p principal, the amount deposited
                 ‘r annual rate of interest
                 ‘c number of times interest is compounded per year
                 ‘n number of years
                 Dim i As Double  ‘interest rate per period
                 Dim m As Double  ‘total number of times interest is compounded
                 i = r / c
                 m = c * n
                 Return p * ((1 + i) ^ m)
               End function

                              1: The following program uses the Hypotenuse function.



















                          Object              Property          Setting

                          frmPythagoras       Text              Right Triangle
                          lblSideOne          AutoSize          False
                                              Text              Length of one side
                          txtSideOne
                          lblSideTwo          AutoSize          False
                                              Text              Length of other side
                          txtSideTwo
                          btnCalculate        Text              Calculate Hypotenuse
                          lblHyp              AutoSize          False
                                              Text              Length of Hypotenuse
                          txtHyp              ReadOnly          True




                                      LOVELY PROFESSIONAL UNIVERSITY                        187
   188   189   190   191   192   193   194   195   196   197   198