[RESOLVED] [2005] help me write a class
I need some help with this problem. I cant figure out where im going wrong in my code.
Create a class called clsTaxReturn. This class should have a property for income (and a private variable to store the income); negative incomes are not allowed. Add a read-only property that returns the income as a formatted string (that is, formatted as currency, $10,000 for 10000, for example). Add functions that return the income tax and insurance tax. As before:
a. Income tax is 15% for the first $10,000 and 25% of the income in excess of $10,000 (just as in a previous question)
b. Insurance tax is 7.75% of the first $50,000; income above $50,000 has no insurance tax. That is, an income of $25,000 would have 7.75% of all 25,000 to pay, while an income of $65,000 would only pay 7.75% of 50,000, not 7.75% of 65,000.
Write a program to test this class.
Here is what I have for my code.
please help
VB Code:
Public Class clsTaxReturn
Private decIncomeValue As Decimal
Private Value As Decimal
Public Event DataError(ByVal sErrorMsg As String)
Public Sub ComputeTax(ByRef decIncomeValue As Decimal, ByRef decIncomeTax As Decimal, ByRef decInsurance As Decimal)
If decIncomeValue <= 10000 Then
decIncomeTax = decIncomeValue * 0.15
Else
decIncomeTax = decIncomeValue * 0.25
End If
If decIncomeValue <= 50000 Then
decInsurance = decIncomeValue * 0.0775
Else
decInsurance = 0
End If
End Sub
Public Property Income() As Decimal
Get
Return decIncomeValue
End Get
Set(ByVal value As Decimal)
If value >= 0 Then
decIncomeValue = value
Else
RaiseEvent DataError("Income cannot be negative.")
End If
End Set
End Property
ReadOnly Property Currency() As String
Get
Return (Format(decIncomeValue, "$##,###"))
End Get
End Property
Private Sub clsTaxReturn_DataError(ByVal sErrorMsg As String) Handles Me.DataError
End Sub
End Class
Imports MyClasses
Public Class Form1
Dim WithEvents Amount As New clsTaxReturn
Private Sub Amount_dataError(ByVal sErrorMsg As String)
MessageBox.Show(sErrorMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Sub
Amount.decIncomeValue = IncomeValue.text
lblInsurance.text = Amount.decInsurance
lblIncome.text = Amount.decIncome
End Class
Re: [2005] help me write a class
I dont have time to write the whole thing but if you tell us what error(s) or so you are getting I will be glad to help guide you to fix it.
Re: [2005] help me write a class
For one, you can replace
VB Code:
Return (Format(decIncomeValue, "$##,###"))
with
VB Code:
Return decIncomeValue.ToString("c")