2017-11-07 1 views
-2

절차 및 기능을 사용하여 소득세 계산기를 만들려고합니다. 코드는 설명이 있어야합니다. 모든 것이 0의 값을 반환합니다. 누군가 내가 잘못 가고있는 부분에 대해 약간의 통찰력을 줄 수 있습니까?Visual Basic 절차 및 절차

Partial Class TaxCalcualtor 
Inherits System.Web.UI.Page 
Private totalWages As Decimal 
Private taxesWithheld As Decimal 
Private deductions As Integer 
Private married As Boolean 
Private taxLiability As Decimal 
Private federalTaxes As Decimal 
Private stateTaxes As Decimal 
Private localTaxes As Decimal 

Function SingleFunction(ByVal totalWages As Decimal, ByVal married As Boolean, ByVal taxLiability As Decimal) As Decimal 
    Dim taxRate As Decimal 
    totalWages = CDec(TextBoxWages.Text) 
    If married = False And totalWages < 25000.0 Then 
     taxRate = 0.15 
    ElseIf married = False And totalWages >= 25000.0 And totalWages < 45000.0 Then 
     taxRate = 0.18 
    ElseIf married = False And totalWages >= 45000.0 And totalWages < 65000.0 Then 
     taxRate = 0.22 
    ElseIf married = False And totalWages >= 65000.0 And totalWages < 85000.0 Then 
     taxRate = 0.28 
    ElseIf married = False And totalWages >= 85000.0 And totalWages < 100000.0 Then 
     taxRate = 0.32 
    ElseIf married = False And totalWages >= 100000.0 Then 
     taxRate = 0.35 
    End If 
    taxLiability = taxRate * totalWages 
    Return taxLiability 
End Function 

Function SingleMarriedFunction(ByVal totalWages As Decimal, ByVal married As Boolean, ByVal taxLiability As Decimal) As Decimal 
    Dim taxRate As Decimal 
    totalWages = CDec(TextBoxWages.Text) 
    If married = True And totalWages < 25000.0 Then 
     taxRate = 0.13 
    ElseIf married = True And totalWages >= 25000.0 And totalWages < 45000.0 Then 
     taxRate = 0.16 
    ElseIf married = True And totalWages >= 45000.0 And totalWages < 65000.0 Then 
     taxRate = 0.18 
    ElseIf married = True And totalWages >= 65000.0 And totalWages < 85000.0 Then 
     taxRate = 0.2 
    ElseIf married = True And totalWages >= 85000.0 And totalWages < 100000.0 Then 
     taxRate = 0.22 
    ElseIf married = True And totalWages >= 100000.0 Then 
     taxRate = 0.24 
    End If 
    taxLiability = taxRate * totalWages 
    Return taxLiability 
End Function 

Function FederalTax(ByVal taxWithheld As Decimal, ByVal taxLiability As Decimal, ByVal deductions As Integer) As Decimal 
    Dim federalTaxes As Decimal 
    taxesWithheld = CDec(TextBoxTaxesWithheld.Text) 
    federalTaxes = taxWithheld - taxLiability - (deductions * 750) 
    Return federalTaxes 
End Function 

Function StateTax(ByVal totalWages As Decimal) As Decimal 
    Dim stateTaxes As Decimal 
    totalWages = CDec(TextBoxWages.Text) 
    stateTaxes = totalWages * 0.06 
    Return stateTaxes 
End Function 

Function LocalTax(ByVal totalWages As Decimal) As Decimal 
    Dim localTaxes As Decimal 
    totalWages = CDec(TextBoxWages.Text) 
    localTaxes = totalWages * 0.01 
    Return localTaxes 
End Function 

Sub DisplayData() 
    Label7.Text += "Tax Liability: " + CStr(taxLiability) 
    Label7.Text += "Federal Taxes: " + CStr(federalTaxes) 
    Label7.Text += "State Taxes: " + CStr(stateTaxes) 
    Label7.Text += "Local Taxes: " + CStr(localTaxes) 
End Sub 

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    DisplayData() 
End Sub 
End Class 
+0

원하는 동작 : 계산 세금 책임, 연방, 주 및 지방 세금 문제 : 모든 값은 당신이 초기화 된 적이없는 값을 표시하는 0 – Bob

+0

을 반환하는이/수정했습니다. 코드가 더 이상 없으면 * taxLiability *는 절대로 수정되지 않습니다. 계산 함수는 절대로 호출되지 않습니다. – Bob

+0

"SingleFunction"및/또는 "SingleMarriedFunction"을 절대 호출하지 않습니다. 또한 아무것도 변경하지 MarriedFunction이라고해서는 안됩니다. 또한 전역 변수는 함수에서 전달하는 것과 동일한 로컬 변수 이름으로 호출하면 안됩니다. 함수의 목적은 전달한 모든 정보에서 값을 반환하는 것입니다. 당신은 여러 곳에서 세금 계산을 변경하고 있지만 그것은 또한 많은 장소에서 선언됩니다. 그 때문에 혼란스러워하고 있습니다. 컴퓨터는 당신이 정말로 원하는 마녀 하나를 알지 못해 당신에게 지역의 것을 돌려줍니다. – Chillzy

답변

1

여기 있습니다. 당신이 내 것과 당신의 차이점을 이해할 수 있도록 내가 한 일을보십시오. 또한 TextBoxDeductions라는 텍스트 상자가 있다고 가정했습니다. 결혼 여부와 상관없이 클릭하기위한 CheckBox가 있어야합니다. 이 CheckBox는 CheckBoxMarried를 호출했습니다. 나는 당신의 2 개의 함수 SingleFunction과 SingleMarriedFunction을 결합했다. 희망은 당신을 위해 그 마음을 만듭니다!

Function GetTaxLiability(ByVal totalWages As Decimal, ByVal married As Boolean) As Decimal 
     Dim taxRate As Decimal 
     If married = True And totalWages < 25000.0 Then 
      taxRate = 0.13 
     ElseIf married = True And totalWages >= 25000.0 And totalWages < 45000.0 Then 
      taxRate = 0.16 
     ElseIf married = True And totalWages >= 45000.0 And totalWages < 65000.0 Then 
      taxRate = 0.18 
     ElseIf married = True And totalWages >= 65000.0 And totalWages < 85000.0 Then 
      taxRate = 0.2 
     ElseIf married = True And totalWages >= 85000.0 And totalWages < 100000.0 Then 
      taxRate = 0.22 
     ElseIf married = True And totalWages >= 100000.0 Then 
      taxRate = 0.24 
     End If 
     If married = False And totalWages < 25000.0 Then 
      taxRate = 0.15 
     ElseIf married = False And totalWages >= 25000.0 And totalWages < 45000.0 Then 
      taxRate = 0.18 
     ElseIf married = False And totalWages >= 45000.0 And totalWages < 65000.0 Then 
      taxRate = 0.22 
     ElseIf married = False And totalWages >= 65000.0 And totalWages < 85000.0 Then 
      taxRate = 0.28 
     ElseIf married = False And totalWages >= 85000.0 And totalWages < 100000.0 Then 
      taxRate = 0.32 
     ElseIf married = False And totalWages >= 100000.0 Then 
      taxRate = 0.35 
     End If 
     Return taxRate * totalWages 
    End Function 

    Function FederalTax(ByVal taxWithheld As Decimal, ByVal taxLiability As Decimal, ByVal deductions As Integer) As Decimal 
     Return taxWithheld - taxLiability - (deductions * 750) 
    End Function 

    Function StateTax(ByVal totalWages As Decimal) As Decimal 
     Return totalWages * 0.06 
    End Function 

    Function LocalTax(ByVal totalWages As Decimal) As Decimal 
     Return totalWages * 0.01 
    End Function 

    Sub DisplayData() 
     Dim TaxLiability As Decimal 
     If CheckBoxMarried.Checked = True Then 
      TaxLiability = GetTaxLiability(CDec(TextBoxWages.Text), True) 
     Else 
      TaxLiability = GetTaxLiability(CDec(TextBoxWages.Text), False) 
     End If 

     Label7.Text += "Tax Liability: " + CStr(TaxLiability) 
     Label7.Text += "Federal Taxes: " + CStr(FederalTax(CDec(TextBoxTaxesWithheld.Text), TaxLiability, CDec(TextBoxDeductions.text))) 
     Label7.Text += "State Taxes: " + CStr(StateTax(CDec(TextBoxWages.Text))) 
     Label7.Text += "Local Taxes: " + CStr(LocalTax(CDec(TextBoxWages.Text))) 
    End Sub 

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     DisplayData() 
    End Sub