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

Unit 6: VB Control Structure


                 End If
               End Sub
               [Run, type 7 into both text boxes, and press the button.]


               If blocks allow us to define functions whose values are not determined by a simple formula. The
               function in  10 uses an If block.


                              6: The Social Security or FICA tax has two components the Social Security
                                benefits tax, which in 2005 is 6.2 percent on the first $90,000 of earnings for
                                the year, and the Medicare tax, which is 1.45 percent of earnings. The following
                                program calculates an employee’s FICA tax for the current pay period.

                     Object              Property          Setting
                     frm FICA            Text              FICA Taxes
                     lblToDate           Text              Total earnings for this year prior to the
                                                           current pay period:
                     txtToDate
                     lblCurrent          Text              Earnings for the current pay period:
                     txtCurrent
                     btnCalculate        Text              Calculate FICA Taxes
                     lblTax              Text              FICA taxes for the current pay period:
                     txtTax              ReadOnly          True






















               Private Sub btnCalculate_Click(...) Handles btnCalculate.Click
                 Dim ficaTaxes As Double
                 ficaTaxes = CalcFICA(CDbl (txtToDate.Text), CDbl (txtCurrent.Text))
                 txtTax.Text = FormatCurrency(ficaTaxes)
               End Sub
               Function CalcFICA(ByVal ytdEarnings As Double, _



                                      LOVELY PROFESSIONAL UNIVERSITY                        133
   134   135   136   137   138   139   140   141   142   143   144