View Single Post
Old Jan 17th, 2007, 8:31 AM   #1
VBuser
Newbie
 
Join Date: Jan 2007
Posts: 3
Rep Power: 0 VBuser is on a distinguished road
Question Plz Help - Visual Basic .net/visual C++ .net Code

Hi! Plz help anyone!!! I wrote this program from a visual basic .net book. It works fine but when i wanna write the same program using visual c++ .net code i get errors. Im using Visual studio.net 2003


   Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intHours, intAllow As Integer, sngRate As Single
        ' display hours worked
        For intHours = 1 To 50
            Me.HoursList.Items.Add(intHours)
        Next intHours
        'display pay rates

        For sngRate = 6 To 12 Step 0.5
            Me.RateList.Items.Add(Format(sngRate, "standard"))
        Next sngRate

        'display witholding allowances
        For intAllow = 0 To 10
            Me.AllowList.Items.Add(intAllow)
        Next intAllow
        'select default item in each list box
        Me.HoursList.SelectedItem = 40
        Me.RateList.SelectedIndex = 0
        Me.AllowList.SelectedIndex = 0


    End Sub

    Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click
        Dim intHours As Integer
        Dim sngRate, sngGross, sngFWT, sngFICA, sngNet As Single
        'assign selected items to variables
        intHours = Me.HoursList.SelectedItem
        sngRate = Me.RateList.SelectedItem

        'calculate gross pay
        If intHours <= 40 Then
            sngGross = intHours * sngRate
        Else
            sngGross = 40 * sngRate + (intHours - 40) * sngRate * 1.5
        End If
        'calculate FWT
        sngFWT = GetFwtTax(sngGross)
        'calculate fica tax
        sngFICA = sngGross * 0.0765
        'round gross pay, fwt and fica tax
        sngGross = Math.Round(sngGross, 2)
        sngFWT = Math.Round(sngFWT, 2)
        sngFICA = Math.Round(sngFICA, 2)
        'calculate net pay
        sngNet = sngGross - sngFWT - sngFICA
        'display calculated amounts
        Me.GrossLabel.Text = Format(sngGross, "currency")
        Me.FWTLabel.Text = Format(sngFWT, "currency")
        Me.FICALabel.Text = Format(sngFICA, "currency")
        Me.NetLabel.Text = Format(sngNet, "currency")
    End Sub

    Private Function GetFwtTax(ByVal sngWeekPay As Single) As Single
        Dim intAllow As Integer, sngTaxWages, sngTax As Single
        'assign number of witholding allowances to a variable
        intAllow = Me.AllowList.SelectedItem

        'calculate taxable wages
        sngTaxWages = sngWeekPay - intAllow * 55.77
        'determine marital status then calculate FWT
        If Me.SingleRadio.Checked = True Then
            Select Case sngTaxWages
                Case Is <= 51
                    sngTax = 0
                Case Is <= 552
                    sngTax = 0.15 * (sngTaxWages - 51)
                Case Is <= 1196
                    sngTax = 75.15 + 0.28 * (sngTaxWages - 552)
                Case Is <= 2662
                    sngTax = 255.47 + 0.31 * (sngTaxWages - 1196)
                Case Is <= 5750
                    sngTax = 709.93 + 0.36 * (sngTaxWages - 2662)
                Case Else
                    sngTax = 1821.61 + 0.396 * (sngTaxWages - 5750)
            End Select
        Else    'marriedradio is selected
            Select Case sngTaxWages
                Case Is <= 124
                    sngTax = 0
                Case Is <= 960
                    sngTax = 0.15 * (sngTaxWages - 124)
                Case Is <= 2023
                    sngTax = 125.4 + 0.28 * (sngTaxWages - 960)
                Case Is <= 3292
                    sngTax = 423.04 + 0.31 * (sngTaxWages - 2023)
                Case Is <= 5809
                    sngTax = 816.43 + 0.36 * (sngTaxWages - 3292)
                Case Else
                    sngTax = 1722.55 + 0.396 * (sngTaxWages - 5809)
            End Select
        End If
        'return FWT
        Return sngTax
    End Function

    
    Private Sub ClearLabels(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles NameTextBox.TextChanged, HoursList.SelectedValueChanged, _
            RateList.SelectedValueChanged, AllowList.SelectedValueChanged, _
            MarriedRadio.Click, SingleRadio.Click

        Me.GrossLabel.Text = ""
        Me.FWTLabel.Text = ""
        Me.FICALabel.Text = ""
        Me.NetLabel.Text = ""
    End Sub

    Private Sub NameTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameTextBox.Enter
        Me.NameTextBox.SelectAll()
    End Sub

End Class
VBuser is offline   Reply With Quote