Results 1 to 2 of 2

Thread: Function Procedure

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    14

    Function Procedure

    I need to write a Function Procedure that will produce an amount displayed in a TaxLabel after calling it from my menu item calculate event.

    Code:
    Private Function TaxAmount(ByVal TaxAmountDecimal As Decimal) As Decimal
            'Declare variable for calculations.
            Dim OutputSubtotal_Decimal As Decimal
            'Determine tax amount.
            Return 0.08D * OutputSubtotal_Decimal
        End Function
    Code:
    Dim TaxDecimal As Decimal
            Dim AmountDue_Decimal As Decimal
            Dim CarSalesPrice_Decimal As Decimal
            Dim Accessories_Decimal As Decimal
            Dim OutputSubtotal_Decimal As Decimal
            Dim OutputTotal_Decimal As Decimal
            Dim TaxAmount_Decimal As Decimal
            Dim TradeInAllowance_Decimal As Decimal
    Code:
    OutputSubtotal_Decimal = CarSalesPrice_Decimal + Accessories_Decimal
                    OutputTotal_Decimal = OutputSubtotal_Decimal + TaxDecimal
                    AmountDue_Decimal = OutputTotal_Decimal - TradeInAllowance_Decimal
                    TaxDecimal = OutputSubtotal_Decimal + TaxAmount_Decimal
    Code:
    AmountLabel.Text = AmountDue_Decimal.ToString("c2")
                    AccessoriesLabel.Text = Accessories_Decimal.ToString
                    OutputSubTotalLabel.Text = OutputSubtotal_Decimal.ToString
                    TaxLabel.Text = TaxAmount(Decimal.Parse _
                                              (TradeInAllowanceTextBox.Text)).ToString
                    OutputTotalLabel.Text = OutputTotal_Decimal.ToString
                    TradeInAllowanceTextBox.Text = TradeInAllowance_Decimal.ToString
    I'm only getting: $0.00 in the TaxLabel? After stepping thru the program, I found the error is in the, Function statement. After following several different examples, I'm still not getting the proper tax amount displayed?

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Function Procedure

    I have not gone through all your code. Just the TaxAmount Function. I have found problems with it.
    - The function takes a parameter (ByVal TaxAmountDecimal As Decimal) but it does not use it at all.
    - It declares a variable Dim OutputSubtotal_Decimal As Decimal but never assigns it a value
    - Returns the value of 0.08 times an empty variable.

    maybe this works:

    vb.net Code:
    1. Private Function TaxAmount(ByVal TaxAmountDecimal As Decimal) As Decimal
    2.         Return 0.08D * TaxAmountDecimal
    3. End Function
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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