Results 1 to 8 of 8

Thread: [RESOLVED] [2005] help me write a class

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    59

    Resolved [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:
    1. Public Class clsTaxReturn
    2.  
    3.     Private decIncomeValue As Decimal
    4.     Private Value As Decimal
    5.  
    6.     Public Event DataError(ByVal sErrorMsg As String)
    7.  
    8.     Public Sub ComputeTax(ByRef decIncomeValue As Decimal, ByRef decIncomeTax As Decimal, ByRef decInsurance As Decimal)
    9.  
    10.        
    11.  
    12.         If decIncomeValue <= 10000 Then
    13.  
    14.             decIncomeTax = decIncomeValue * 0.15
    15.  
    16.         Else
    17.  
    18.             decIncomeTax = decIncomeValue * 0.25
    19.  
    20.         End If
    21.  
    22.         If decIncomeValue <= 50000 Then
    23.  
    24.             decInsurance = decIncomeValue * 0.0775
    25.  
    26.         Else
    27.  
    28.             decInsurance = 0
    29.  
    30.         End If
    31.     End Sub
    32.  
    33.     Public Property Income() As Decimal
    34.         Get
    35.             Return decIncomeValue
    36.         End Get
    37.         Set(ByVal value As Decimal)
    38.             If value >= 0 Then
    39.                 decIncomeValue = value
    40.             Else
    41.                 RaiseEvent DataError("Income cannot be negative.")
    42.             End If
    43.         End Set
    44.     End Property
    45.  
    46.     ReadOnly Property Currency() As String
    47.         Get
    48.             Return (Format(decIncomeValue, "$##,###"))
    49.         End Get
    50.     End Property
    51.  
    52.     Private Sub clsTaxReturn_DataError(ByVal sErrorMsg As String) Handles Me.DataError
    53.  
    54.     End Sub
    55. End Class
    56. Imports MyClasses
    57. Public Class Form1
    58.     Dim WithEvents Amount As New clsTaxReturn
    59.  
    60.     Private Sub Amount_dataError(ByVal sErrorMsg As String)
    61.         MessageBox.Show(sErrorMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    62.     End Sub
    63. Amount.decIncomeValue = IncomeValue.text
    64. lblInsurance.text = Amount.decInsurance
    65. lblIncome.text = Amount.decIncome
    66.  
    67. End Class
    Last edited by bhs00; Jan 8th, 2007 at 04:33 PM. Reason: no title

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005]

    Welcome to the Forums.

    What is your question?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    59

    Re: [2005]

    The question is the first part I posted. The second part is what I have for it. I was wondering if someone could look at my code and give me a hand on how to fix it.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005]

    But you need to tell us more then whats wrong with it.
    Are you getting an error and if so where? Sounds like a school project. If you tell us whats wrong with it that makes it easier to ehlp fix it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    59

    Re: [2005]

    yes it is a school problem and I just need some help. My school is online so there is no way for me to get help. The class question is in the original post and I would like for someone to look at my code and see if it will work. I get no errors. But I also have no idea how to incorporate this class that I wrote into a program. Ive done this problem before, but not with using a class to simplify. I rewrote some of my code and here it is. please help

    VB Code:
    1. Public Class clsTaxReturn
    2.  
    3.     Private decIncome As Decimal
    4.  
    5.     Public Event DataError(ByVal sErrorMsg As String)
    6.  
    7.  
    8.     Public Sub ComputeTax(ByRef decIncomeValue As Decimal, ByRef decincometax As Decimal, ByRef decInsurance As Decimal)
    9.         If decIncomeValue <= 10000 Then
    10.             decincometax = decIncomeValue * 0.15
    11.         Else
    12.             decincometax = decIncomeValue * 0.25
    13.         End If
    14.  
    15.         If decIncomeValue <= 50000 Then
    16.             decInsurance = decIncomeValue * 0.0775
    17.         Else
    18.             decInsurance = 0
    19.         End If
    20.     End Sub
    21.  
    22.     Public Property income() As Decimal
    23.         Get
    24.             Return decIncome
    25.         End Get
    26.         Set(ByVal value As Decimal)
    27.             If value >= 0 Then
    28.                 decIncome = value
    29.             Else
    30.                 RaiseEvent DataError("Income cannot be negative.")
    31.             End If
    32.         End Set
    33.     End Property
    34.  
    35.     ReadOnly Property Currency() As String
    36.         Get
    37.             Return (Format(decIncome, "$##,###"))
    38.         End Get
    39.     End Property
    40.  
    41. End Class

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    59

    Re: [2005]

    could you tell me if it looks like it will work for my problem?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2005] help me write a class

    For one, you can replace
    VB Code:
    1. Return (Format(decIncomeValue, "$##,###"))
    with
    VB Code:
    1. Return decIncomeValue.ToString("c")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width