Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27046

VS 2008 Software Sales Application

$
0
0
Hey, so I'm sure many of you have completed the Software Sales application. I am having trouble with what I would say is the simple multiplication behind it? For some reason.. My numbers aren't adding up. Below is my code if you want to have a look. Sorry if it is a bit messy, but I added remarks to hopefully make it readable.

Basically, the application is suppose to multiply the input for Package A, B, and C by their respectable values of $99, $199, and $299. And then based on what number is entered discount it on that. So the only one that works is Package C. Package A and B do not calculate out to be $1,188.00 and $8,955.00 which they're suppose to be. Anyone have any clue about this math?

Code:

Public Class Form1

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        'Declaring variables

        Dim intPackageAQuantity, intPackageBQuantity, intPackageCQuantity As Integer
        Dim intPackageAPrice, intPackageBPrice, intPackageCPrice As Integer
        Dim decPackageADiscount, decPackageBDiscount, decPackageCDiscount As Decimal
        Dim intPackageAFinal, intPackageBFinal, intPackageCFinal As Integer
        Dim intGrandTotal As Integer

        'TryParse to make sure the numbers entered in the textbox are in fact an integer
        If Integer.TryParse(txtPackageAQuantity.Text, intPackageAQuantity) AndAlso _
        Integer.TryParse(txtPackageBQuantity.Text, intPackageBQuantity) AndAlso _
        Integer.TryParse(txtPackageCQuantity.Text, intPackageCQuantity) Then
            'Checking to make sure the values entered are not negative
            If (intPackageAQuantity < 0) Or (intPackageBQuantity < 0) Or (intPackageCQuantity < 0) Then
                MessageBox.Show("You cannot use negative numbers!", "Important Message")
            Else
                'Determing what discount to use based on the input entered in
                Select Case CInt(txtPackageAQuantity.Text)
                    Case 0 To 9
                        decPackageADiscount = 0.0
                    Case 10 To 19
                        decPackageADiscount = 0.2
                    Case 20 To 49
                        decPackageADiscount = 0.3
                    Case 50 To 99
                        decPackageADiscount = 0.4
                    Case Is > 100
                        decPackageADiscount = 0.5
                End Select

                Select Case CInt(txtPackageBQuantity.Text)
                    Case 0 To 9
                        decPackageBDiscount = 0.0
                    Case 10 To 19
                        decPackageBDiscount = 0.2
                    Case 20 To 49
                        decPackageBDiscount = 0.3
                    Case 50 To 99
                        decPackageBDiscount = 0.4
                    Case Is > 100
                        decPackageBDiscount = 0.5
                End Select

                Select Case CInt(txtPackageCQuantity.Text)
                    Case 0 To 9
                        decPackageCDiscount = 0.0
                    Case 10 To 19
                        decPackageCDiscount = 0.2
                    Case 20 To 49
                        decPackageCDiscount = 0.3
                    Case 50 To 99
                        decPackageCDiscount = 0.4
                    Case Is > 100
                        decPackageCDiscount = 0.5
                End Select

                'Assigning PackageA, B, C their respectable values
                intPackageAPrice = 99
                intPackageBPrice = 199
                intPackageCPrice = 299

                'Multiplying Package's by their price and amt entered in the txtbox
                'Then multiplying them by their discounted price from the Select Case above
                intPackageAFinal = (intPackageAPrice * intPackageAQuantity) * decPackageADiscount
                intPackageBFinal = (intPackageBPrice * intPackageBQuantity) * decPackageBDiscount
                'PackageC is the only one that comes out correct
                intPackageCFinal = (intPackageCPrice * intPackageCQuantity) * decPackageCDiscount

                'Finding the grand total
                intGrandTotal = intPackageAFinal + intPackageBFinal + intPackageCFinal

                'Displaying everything in a label
                lblFinalPrices.Text = "Package A: " & intPackageAFinal.ToString("c") & Environment.NewLine & _
                "Package B: " & intPackageBFinal.ToString("c") & Environment.NewLine & _
                "Package C: " & intPackageCFinal.ToString("c") & Environment.NewLine & _
                "Grand Total: " & intGrandTotal.ToString("c")

            End If
        End If

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        lblFinalPrices.Text = ""
        txtPackageAQuantity.Clear()
        txtPackageBQuantity.Clear()
        txtPackageCQuantity.Clear()
        txtPackageAQuantity.Focus()
    End Sub

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

Thank you for reading

Viewing all articles
Browse latest Browse all 27046

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>