Results 1 to 4 of 4

Thread: Calculation Error.....Any ideas? [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    5

    Calculation Error.....Any ideas? [RESOLVED]

    I am taking a beginning VB.NET course, I am having trouble getting this project to calculate properly. I think the calculations are in the wrong place, cause when you uncheck a box (deselect) it continues to hold that value in memory and add it to the total. It also adds all values no matter how many check boxes you check or which discount you apply. Any help would be really appreciated!! We are required to use Option Strict in all programs for this course.

    Jennifer





    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.  
    7.  
    8. #End Region
    9.     Const mdecMANICURE_PRICE As Decimal = 35D
    10.     Const mdecMAKEOVER_PRICE As Decimal = 125D
    11.     Const mdecHAIRSTYLING_PRICE As Decimal = 60D
    12.     Const mdecPERMANENTMAKEUP_PRICE As Decimal = 200D
    13.     Const mdecDISCOUNT10 As Decimal = 0.9D
    14.     Const mdecDISCOUNT20 As Decimal = 0.8D
    15.     Dim decSubtotal As Decimal
    16.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    17.         'Exit the project
    18.         Me.Close()
    19.     End Sub
    20.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    21.  
    22.         If chkMakeover.Checked = True Then
    23.             lblMakeover.Text = CStr(mdecMAKEOVER_PRICE)
    24.             lblMakeover.Text = FormatCurrency(mdecMAKEOVER_PRICE)
    25.  
    26.         ElseIf chkMakeover.Checked = False Then
    27.             lblMakeover.Text = ""
    28.             decSubtotal = decSubtotal + mdecMAKEOVER_PRICE
    29.         End If
    30.  
    31.         If chkHairstyling.Checked = True Then
    32.             lblHairstyling.Text = CStr(mdecHAIRSTYLING_PRICE)
    33.             lblHairstyling.Text = FormatCurrency(mdecHAIRSTYLING_PRICE)
    34.  
    35.         ElseIf chkHairstyling.Checked = False Then
    36.             lblHairstyling.Text = ""
    37.             decSubtotal = decSubtotal + mdecHAIRSTYLING_PRICE
    38.         End If
    39.  
    40.         If chkManicure.Checked = True Then
    41.             lblManicure.Text = CStr(mdecMANICURE_PRICE)
    42.             lblManicure.Text = FormatCurrency(mdecMANICURE_PRICE)
    43.         ElseIf chkManicure.Checked = False Then
    44.             lblManicure.Text = ""
    45.             decSubtotal = decSubtotal + mdecMANICURE_PRICE
    46.         End If
    47.  
    48.         If chkPermanentmakeup.Checked = True Then
    49.             lblPermanentmakeup.Text = CStr(mdecPERMANENTMAKEUP_PRICE)
    50.             lblPermanentmakeup.Text = FormatCurrency(mdecPERMANENTMAKEUP_PRICE)
    51.         ElseIf chkPermanentmakeup.Checked = False Then
    52.             lblPermanentmakeup.Text = ""
    53.             decSubtotal = decSubtotal + mdecPERMANENTMAKEUP_PRICE
    54.         End If
    55.  
    56.         If radDiscount10.Checked = True Then
    57.             decSubtotal = decSubtotal * mdecDISCOUNT10
    58.         ElseIf radDiscount20.Checked = True Then
    59.             decSubtotal = decSubtotal * mdecDISCOUNT20
    60.         ElseIf radDiscountNo.Checked = True Then
    61.             decSubtotal = decSubtotal * 1
    62.         End If
    63.         lblTotalDue.Text = FormatCurrency(decSubtotal)
    64.  
    65.     End Sub
    66.  
    67.     Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    68.         If lblTotalDue.Text <> "" Then
    69.             If IsNumeric(lblTotalDue.Text) Then
    70.  
    71.                 chkMakeover.Checked = False
    72.                 chkHairstyling.Checked = False
    73.                 chkManicure.Checked = False
    74.                 chkPermanentmakeup.Checked = False
    75.                 lblTotalDue.Text = ""
    76.                 lblMakeover.Text = ""
    77.                 lblHairstyling.Text = ""
    78.                 lblManicure.Text = ""
    79.                 lblPermanentmakeup.Text = ""
    80.                 decSubtotal = 0
    81.                 radDiscount10.Checked = False
    82.                 radDiscount20.Checked = False
    83.                 radDiscountNo.Checked = False
    84.                 txtCustomerName.Clear()
    85.                 txtCustomerName.Focus()
    86.             End If
    87.  
    88.         End If
    89.     End Sub
    90. End Class
    Attached Files Attached Files
    Last edited by poodle726; Nov 30th, 2003 at 10:44 AM.

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