5 Replies - 506 Views - Last Post: 19 October 2017 - 11:10 AM Rate Topic: -----

#1 Ironxlotus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-October 17

Software Sales Application HELP! VB

Posted 18 October 2017 - 11:45 AM

I'm working on a project that is trying to calculate the discount on three different kinds of packages, each worth different prices.

what we are given is
package A= $99
package B= $199
package C= $299

Quantity Discount
10 through 19 20%
20 through 49 30%
50 through 99 40%
100 or more 50%

everything is supposed to show up on the "lblGrand" for the user to see

what I'm trying to figure out is how to write the code the price of each package and then what discount each would get



Public Class Form1
    Dim PackA As Single
    Dim PackB As Single
    Dim PackC As Single
    Dim TotalA As Decimal
    Dim TotalB As Decimal
    Dim TotalC As Decimal
    Dim Grand As Decimal
    Dim PriceA As Decimal
    Dim PriceB As Decimal
    Dim PriceC As Decimal
    Dim Discount As Decimal
    Dim PercentA As Decimal
    Dim PercentB As Decimal
    Dim PercentC As Decimal
    Dim PercentD As Decimal



    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtPackA.Clear()
        txtPackB.Clear()
        txtPackC.Clear()
        lblTotal.Text = String.Empty
    End Sub

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

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


        Select Case PackA
            Case Is < 10
                Discount = Val(txtPackA.Text) * 99
                TotalA = Discount - PercentA
            Case 10 To 19
                Discount = ((Val(txtPackA.Text) * 99) * PercentB)
                TotalA = Discount - PercentB
            Case 20 To 50
                Discount = ((Val(txtPackA.Text) * 99) * PercentC)
                TotalA = Discount - PercentC
            Case 51 To 100
                Discount = ((Val(txtPackA.Text) * 99) * PercentD)
                TotalA = Discount - PercentD
        End Select

        Select Case PackB
            Case Is < 10
                Discount = Val(txtPackB.Text) * 99
                TotalB = Discount - PercentA
            Case 10 To 19
                Discount = ((Val(txtPackB.Text) * 99) * PercentB)
                TotalB = Discount - PercentB
            Case 20 To 50
                Discount = ((Val(txtPackB.Text) * 99) * PercentC)
                TotalB = Discount - PercentC
            Case 51 To 100
                Discount = ((Val(txtPackB.Text) * 99) * PercentD)
                TotalB = Discount - PercentD
        End Select

        Select Case PackC
            Case Is < 10
                Discount = Val(txtPackB.Text) * 99
                TotalC = Discount - PercentA
            Case 10 To 19
                Discount = ((Val(txtPackB.Text) * 99) * PercentB)
                TotalC = Discount - PercentB
            Case 20 To 50
                Discount = ((Val(txtPackB.Text) * 99) * PercentC)
                TotalC = Discount - PercentC
            Case 51 To 100
                Discount = ((Val(txtPackB.Text) * 99) * PercentD)
                TotalC = Discount - PercentD
        End Select

        PercentA = 0.2
        PercentB = 0.3
        PercentC = 0.4
        PercentD = 0.5
        PackA = Val(txtPackA.Text) * 99
        PackB = Val(txtPackB.Text) * 199
        PackC = Val(txtPackC.Text) * 299


        'Calculate Total
        lblTotal.Text = CStr(TotalA - Discount) + CStr(TotalB - Discount) + CStr(TotalC - Discount)


    End Sub
End Class
:code:

This post has been edited by modi123_1: 18 October 2017 - 11:47 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Software Sales Application HELP! VB

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13483
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Software Sales Application HELP! VB

Posted 18 October 2017 - 11:48 AM

What's your question then?
Is there a reason your are converting your numbers to strings in different parts on line 89?
Was This Post Helpful? 0
  • +
  • -

#3 Ironxlotus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-October 17

Re: Software Sales Application HELP! VB

Posted 18 October 2017 - 11:54 AM

View Postmodi123_1, on 18 October 2017 - 11:48 AM, said:

What's your question then?
Is there a reason your are converting your numbers to strings in different parts on line 89?




my question is how do I get the correct number to show on the lblGrand

I forgot to take that out sorry!
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: Software Sales Application HELP! VB

Posted 18 October 2017 - 12:24 PM

That is VB.NET code, not VB6. Moving to VB.NET forum.
Was This Post Helpful? 0
  • +
  • -

#5 jimzcoder  Icon User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 351
  • Joined: 14-November 12

Re: Software Sales Application HELP! VB

Posted 18 October 2017 - 10:49 PM

Hi, by reading reading your code, it seems the problem is on your conversion of textbox value. Try using CDec(textbox.text) to convert the text into decimal datatype instead of val because Val() function converts it to integer data type if i`m not mistaken. Hope it helps :)
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1444
  • View blog
  • Posts: 3,674
  • Joined: 01-February 13

Re: Software Sales Application HELP! VB

Posted 19 October 2017 - 11:10 AM

Quote

my question is how do I get the correct number to show on the lblGrand

Please show us what you get in the label and what you expect to get in the label.

Also, just so you understand, you would not do mathematical calculations such as addition with String types, you would do that with Integer, Decimal, Double, or one of the other numerical types.

Without us knowing what you want, my guess would be that it is the line below that is causing your biggest problem.
        lblTotal.Text = CStr(TotalA - Discount) + CStr(TotalB - Discount) + CStr(TotalC - Discount)



In the above line you are taking (TotalA - Discount) and converting it to a String with CStr(). You are doing the same with the rest. Then you are joining the Strings together with the '+' instead of mathematically adding them. The '+' sign does not do the same thing with String types as it does with actual numeric types.

Adding two Strings like... "5" + "3" would give you "53" instead of 8. Think about that for a minute. You may want to mathematically add them together first, and then convert them to a String to show in the label.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1