Results 1 to 2 of 2

Thread: Help With Calculations

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    1

    Help With Calculations

    I am working on a project and have most of the code completed, but with many errors. The Calculate button is supposed to display:
    - the accessories and finish minus the entered base price in subtotal
    - display the subtotal plus salestax in the total control
    -display the total minus the entered trade-in price in an amount due control

    I thought i understood everything, but the further I went, the more lost and confused I got. Please let me know how I can fix my errors, some of which are listed below:

    -Identifier expected
    -Operator '+' is not defined for types 'System.Windows.Forms.TextBox' and 'System.Windows.Forms.TextBox'.

    All of the operator I used show similar errors. how do I fix this, and the other error? The code is shown below, and i have attached what I have completed.

    Public Class Form1

    Private sub
    Dim Stereo As Decimal
    Dim Leather As Decimal
    Dim CompNav As Decimal
    Dim ExteriorFinish As Decimal
    Dim TaxRate As Decimal

    'Get the price of selected accessory or accessories
    If stereoCheckBox.Checked Then
    Stereo = 425.76
    Else
    Stereo = 0
    End If
    If leatherCheckBox.Checked Then
    Leather = 987.41
    Else
    Leather = 0
    End If
    If navigationCheckBox.Checked Then
    CompNav = 1741.23
    Else
    CompNav = 0
    End If

    'Get the price of selected exterior finish
    If standardRadioButton.Checked Then
    ExteriorFinish = 0
    ElseIf pearlizedRadioButton.Checked Then
    ExteriorFinish = 345.72
    ElseIf customRadioButton.Checked Then
    ExteriorFinish = 599.99
    End If

    'Calculate total of selected accessories and finish
    accessoriesFinish = Stereo + Leather + CompNav + ExteriorFinish
    accessoriesFinishTextBox = FormatNumber(accessoriesFinish)

    End Sub

    Private Sub subtotalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subtotalTextBox.TextChanged
    'Calculate subtotal of accessories and finish and base price
    subtotalTextBox = salesPriceTextBox + accessoriesFinishTextBox
    End Sub

    Private Sub salesTaxTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles salesTaxTextBox.TextChanged
    'Calculate the sales tax on the subtotal
    salesTaxTextBox = subtotalTextBox * 0.08
    End Sub

    Private Sub totalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles totalTextBox.TextChanged
    'Calculate the sum of the subtotal and the sales tax
    totalTextBox = subtotalTextBox + salesTaxTextBox
    End Sub

    Private Sub amountDueTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles amountDueTextBox.TextChanged
    'Calculate the total minus the trade-in alllowance
    amountDueTextBox = totalTextBox - tradeInTextBox
    End Sub

    Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
    'Calculate the total minus the trade-in alllowance
    amountDueTextBox = totalTextBox - tradeInTextBox
    End Sub
    End Class
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Help With Calculations

    Textboxes are objects that are represented by their respective classes in the .NET framework. Classes are made up of fields, property, methods, and events that expose the functionality of the textbox so that you can use it.

    So I imagine here you are looking to get a value from the textbox right? This value you need for calculations is the value that was entered into the textbox right? You need to access the property of the textbox that contains the value of what is entered into it.

    For the textbox (and most winform controls with text values) this is the .text property.

    So if "10" is entered in the subtotalTextBox, you would know this by accessing the subtotalTextBox.Text property:

    Code:
    Messagebox.Show(subtotalTextBox.Text)
    I won't even get into the fact that text in a textbox is a string, and you are trying to do numeric math on text, we can talk about that once you get your initial errors ironed out.

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