11 Replies - 388 Views - Last Post: 30 April 2015 - 01:04 PM Rate Topic: -----

#1 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

VB Combo Box Calculation Help

Posted 30 April 2015 - 10:37 AM

Okay so Iv been working on a calculator Project for my Visual Basic class. Iv used a combination of Radio Buttons and ComboBoxes to piece together a calculator similar to what you use if you where customizing a specific Item on the internet to Buy. My problem is when I go to Click the Calculate button it seems like that it one calculates whats in the Radio Buttons and not in the ComboBoxes. Can Anybody tell me what exactly is going on? (Note I have not coded the Clear Button Yet) I also added an attachment of my program if youd like to see for yourself.

Public Class Form1

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        'This procedure calculates the total of an order.
        Dim decSubtotal As Decimal          'Holds the order subtotal
        Dim decTax As Decimal               'Holds the sales tax
        Dim decTotal As Decimal             'Hold the order total

        decSubtotal = CalcBdyWood() + CalcBdyColor() + CalcNkWood() + CalcNkFrets()
        decTax = decTax_Rate * decSubtotal
        decTotal = CDec(decSubtotal + decTax)

        lblSubTotal.Text = decSubtotal.ToString("c")
        lblTax.Text = decTax.ToString("c")
        lblTotal.Text = decTotal.ToString("c")
    End Sub

    Function CalcBdyWood() As Decimal

        Dim decBdyWood As Decimal

        If cboBdyWood.SelectedText = "Basswood($390)" Then
            decBdyWood = decBdyWood_Basewood
        ElseIf cboBdyWood.SelectedText = "Ash($410)" Then
            decBdyWood = decBdyWood_Ash
        ElseIf cboBdyWood.SelectedText = "Alder($410)" Then
            decBdyWood = decBdyWood_Alder
        ElseIf cboBdyWood.SelectedText = "Maple($430)" Then
            decBdyWood = decBdyWood_Maple
        ElseIf cboBdyWood.SelectedText = "Mahogany($430)" Then
            decBdyWood = decBdyWood_Mahogany
        ElseIf cboBdyWood.SelectedText = "Cherry($510)" Then
            decBdyWood = decBdyWood_Cherry
        End If

        Return decBdyWood


    End Function

    Function CalcBdyColor() As Decimal

        Dim decBdyColor As Decimal

        If radBurst.Checked Then
            decBdyColor = decBdyColor_Burst
        ElseIf radGloss.Checked Then
            decBdyColor = decBdyColor_Gloss
        ElseIf radTransparent.Checked Then
            decBdyColor = decBdyColor_Transparent
        End If

        Return decBdyColor

    End Function

    Function CalcNkWood() As Decimal

        Dim decNkWood As Decimal

        If cboNkWood.SelectedText = "Basswood($130)" Then
            decNkWood = decNkWood_Basewood
        ElseIf cboNkWood.SelectedText = "Ash($150)" Then
            decNkWood = decNkWood_Ash
        ElseIf cboNkWood.SelectedText = "Alder($150)" Then
            decNkWood = decNkWood_Alder
        ElseIf cboNkWood.SelectedText = "Maple($170)" Then
            decNkWood = decNkWood_Maple
        ElseIf cboNkWood.SelectedText = "Mahogany($180)" Then
            decNkWood = decNkWood_Mahogany
        ElseIf cboNkWood.SelectedText = "Cherry($210)" Then
            decNkWood = decNkWood_Cherry
        End If

        Return decNkWood

    End Function

    Function CalcNkFrets() As Decimal

        Dim decNkFrets As Decimal

        decNkFrets = CalcFretSize() + CalcFretMaterial()

        Return decNkFrets

    End Function

    Function CalcFretSize() As Decimal

        Dim decFretSize As Decimal

        If cboFretSize.SelectedText = "XJumbo($45)" Then
            decFretSize = decFretsXJ
        ElseIf cboFretSize.SelectedText = "Jumbo($35)" Then
            decFretSize = decFretsJ
        ElseIf cboFretSize.SelectedText = "Large($25)" Then
            decFretSize = decFretsL
        ElseIf cboFretSize.SelectedText = "Medium($15)" Then
            decFretSize = decFretsM
        End If

        Return decFretSize

    End Function

    Function CalcFretMaterial() As Decimal

        Dim decNkFretMat As Decimal

        If radGold.Checked Then
            decNkFretMat = decFretMat_Gold
        End If

        Return decNkFretMat

    End Function

    'Function CalcTax(ByVal decAmount As Decimal) As Decimal
    '    'This function receives the sale amount and 
    '    'returns the amount of sales tax.
    '    Return decAmount * decTax_Rate
    'End Function

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

Attached File(s)


This post has been edited by andrewsw: 30 April 2015 - 11:15 AM
Reason for edit:: Added [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: VB Combo Box Calculation Help

#2 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 10:47 AM

Apologies for the code. Im new to this and dont quite understand how to Tag my code
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 11:14 AM

Square brackets are not code tags.

How to use code tags:

Attached Image

This post has been edited by andrewsw: 30 April 2015 - 11:15 AM

Was This Post Helpful? 1
  • +
  • -

#4 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 11:22 AM

Okay Here is My From and Module Code with the tags


Module Constants_global
    Public decTax_Rate As Decimal = 0.07D               ' Tax Rate
    Public decBdyWood_Basewood As Decimal = 390D        ' Basewood Body Price
    Public decBdyWood_Ash As Decimal = 410D             ' Ashwood Body Price
    Public decBdyWood_Alder As Decimal = 410D           ' Alder Body Price
    Public decBdyWood_Maple As Decimal = 430D           ' Maple Body Price
    Public decBdyWood_Mahogany As Decimal = 430D        ' Mahogany Body Price
    Public decBdyWood_Cherry As Decimal = 510D          ' Cherry Body Price
    Public decBdyColor_Gloss As Decimal = 100D          ' Gloss Finish Price
    Public decBdyColor_Burst As Decimal = 125D          ' Burst Finish Price
    Public decBdyColor_Transparent As Decimal = 175D
    Public decNkWood_Basewood As Decimal = 125D
    Public decNkWood_Ash As Decimal = 145D
    Public decNkWood_Alder As Decimal = 145D
    Public decNkWood_Maple As Decimal = 165D
    Public decNkWood_Mahogany As Decimal = 165D
    Public decNkWood_Cherry As Decimal = 210D
    Public decFretsXJ As Decimal = 45D
    Public decFretsJ As Decimal = 35D
    Public decFretsL As Decimal = 25D
    Public decFretsM As Decimal = 15D
    Public decFretMat_Gold As Decimal = 40D

End Module



Public Class Form1

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        'This procedure calculates the total of an order.
        Dim decSubtotal As Decimal          'Holds the order subtotal
        Dim decTax As Decimal               'Holds the sales tax
        Dim decTotal As Decimal             'Hold the order total

        decSubtotal = CalcBdyWood() + CalcBdyColor() + CalcNkWood() + CalcNkFrets()
        decTax = decTax_Rate * decSubtotal
        decTotal = CDec(decSubtotal + decTax)

        lblSubTotal.Text = decSubtotal.ToString("c")
        lblTax.Text = decTax.ToString("c")
        lblTotal.Text = decTotal.ToString("c")
    End Sub

    Function CalcBdyWood() As Decimal

        Dim decBdyWood As Decimal

        If cboBdyWood.SelectedText = "Basswood($390)" Then
            decBdyWood = decBdyWood_Basewood
        ElseIf cboBdyWood.SelectedText = "Ash($410)" Then
            decBdyWood = decBdyWood_Ash
        ElseIf cboBdyWood.SelectedText = "Alder($410)" Then
            decBdyWood = decBdyWood_Alder
        ElseIf cboBdyWood.SelectedText = "Maple($430)" Then
            decBdyWood = decBdyWood_Maple
        ElseIf cboBdyWood.SelectedText = "Mahogany($430)" Then
            decBdyWood = decBdyWood_Mahogany
        ElseIf cboBdyWood.SelectedText = "Cherry($510)" Then
            decBdyWood = decBdyWood_Cherry
        End If

        Return decBdyWood


    End Function

    Function CalcBdyColor() As Decimal

        Dim decBdyColor As Decimal

        If radBurst.Checked Then
            decBdyColor = decBdyColor_Burst
        ElseIf radGloss.Checked Then
            decBdyColor = decBdyColor_Gloss
        ElseIf radTransparent.Checked Then
            decBdyColor = decBdyColor_Transparent
        End If

        Return decBdyColor

    End Function

    Function CalcNkWood() As Decimal

        Dim decNkWood As Decimal

        If cboNkWood.SelectedText = "Basswood($130)" Then
            decNkWood = decNkWood_Basewood
        ElseIf cboNkWood.SelectedText = "Ash($150)" Then
            decNkWood = decNkWood_Ash
        ElseIf cboNkWood.SelectedText = "Alder($150)" Then
            decNkWood = decNkWood_Alder
        ElseIf cboNkWood.SelectedText = "Maple($170)" Then
            decNkWood = decNkWood_Maple
        ElseIf cboNkWood.SelectedText = "Mahogany($180)" Then
            decNkWood = decNkWood_Mahogany
        ElseIf cboNkWood.SelectedText = "Cherry($210)" Then
            decNkWood = decNkWood_Cherry
        End If

        Return decNkWood

    End Function

    Function CalcNkFrets() As Decimal

        Dim decNkFrets As Decimal

        decNkFrets = CalcFretSize() + CalcFretMaterial()

        Return decNkFrets

    End Function

    Function CalcFretSize() As Decimal

        Dim decFretSize As Decimal

        If cboFretSize.SelectedText = "XJumbo($45)" Then
            decFretSize = decFretsXJ
        ElseIf cboFretSize.SelectedText = "Jumbo($35)" Then
            decFretSize = decFretsJ
        ElseIf cboFretSize.SelectedText = "Large($25)" Then
            decFretSize = decFretsL
        ElseIf cboFretSize.SelectedText = "Medium($15)" Then
            decFretSize = decFretsM
        End If

        Return decFretSize

    End Function

    Function CalcFretMaterial() As Decimal

        Dim decNkFretMat As Decimal

        If radGold.Checked Then
            decNkFretMat = decFretMat_Gold
        End If

        Return decNkFretMat

    End Function

    'Function CalcTax(ByVal decAmount As Decimal) As Decimal
    '    'This function receives the sale amount and 
    '    'returns the amount of sales tax.
    '    Return decAmount * decTax_Rate
    'End Function

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

End Class


View Postandrewsw, on 30 April 2015 - 11:14 AM, said:

Square brackets are not code tags.

How to use code tags:

Attachment codetags.gif



Thank You! That Helped!
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 11:24 AM

SelectedText is the selected text within the editable portion of the ComboBox. Use .SelectedItem.ToString() instead.
Was This Post Helpful? 1
  • +
  • -

#6 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 12:02 PM

View Postandrewsw, on 30 April 2015 - 11:24 AM, said:

SelectedText is the selected text within the editable portion of the ComboBox. Use .SelectedItem.ToString() instead.



Is this what you mean?

Function CalcBdyWood() As Decimal

        Dim decBdyWood As Decimal

            If cboBdyWood.SelectedItem.ToString() = "Basewood($390)" Then
                decBdyWood = decBdyWood_Basewood
            ElseIf cboBdyWood.SelectedItem.ToString() = "Ash($410)" Then
                decBdyWood = decBdyWood_Ash
            ElseIf cboBdyWood.SelectedItem.ToString() = "Alder($410)" Then
                decBdyWood = decBdyWood_Alder
            ElseIf cboBdyWood.SelectedItem.ToString() = "Maple($430)" Then
                decBdyWood = decBdyWood_Maple
            ElseIf cboBdyWood.SelectedItem.ToString() = "Mahogany($430)" Then
                decBdyWood = decBdyWood_Mahogany
            ElseIf cboBdyWood.SelectedItem.ToString() = "Cherry($510)" Then
                decBdyWood = decBdyWood_Cherry
            End If

        Return decBdyWood


    End Function

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 12:10 PM

Well, does it work? You've gone to the trouble of typing it, why not run it and see?

This post has been edited by andrewsw: 30 April 2015 - 12:11 PM

Was This Post Helpful? 0
  • +
  • -

#8 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 12:13 PM

It Works but then it doesn't. For whatever reason it seems to not want to read the First and last If statements. As in if either Cherry Or Basewood is selected it wont show up in the calculation. Its working better though on that note.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 12:16 PM

There is a debugging tutorial linked in my signature below. Knowing how to debug, and use debugging tools, are essential skills. Take the tutorial and you can step through your code and discover what is going on.
Was This Post Helpful? 1
  • +
  • -

#10 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 12:42 PM

My whole Program Works now and you wouldn't believe what happened. When I input the Text into the Collections property of the Comboboxes. There was an extra SPACE after the a few of the text, And Since it wasnt written as so in the actually code it would skip right over it as a False Statement. Its one of the dumbest mistakes iv ever made.
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 01:00 PM

It did occur to me straightaway that you might have a space between text like "Basewood($390)" but I didn't pursue it ;)
Was This Post Helpful? 0
  • +
  • -

#12 CoreyPell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-April 15

Re: VB Combo Box Calculation Help

Posted 30 April 2015 - 01:04 PM

Haha Thank you soo much! You were a great deal of help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1