Calculator

Growler

Member
Joined
Sep 23, 2010
Messages
13
Programming Experience
Beginner
Hello,

I'm trying to do the following with the Calculate Button:
Display unit price in lblPrice based on Group Number and the Number of Units that the User enters in txtGroupNum and txtUnits:
Quanitity-based Unity Price if Group Number is 501:
- Less than 100 units, unit price = $87.99
- 100 or more unit, unit price = $59.99

Quantity-based Unit Price if Group Number is 062:
- Less than 100, unit price = $109.99
- 100 more more, unit price = $67.99

My code is as follows, but is throwing a lot of casting errors.

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click

        Dim groupNumber As String
        Dim numberOfUnits As Integer
        Dim unitPrice As Double
        Dim totalDue As Double

        groupNumber = txtGroupNum.Text
        numberOfUnits = CInt(txtUnits.Text)
        unitPrice = CDbl(lblPrice.Text)

        'Calculate and display Total Due
        totalDue = unitPrice * CDbl(numberOfUnits)
        lblTotal.Text = totalDue.ToString("c") 'will convert to to $ sign



        If groupNumber = "501" And (numberOfUnits < 100 And numberOfUnits >= 0) Then
            unitPrice = 87.99

        ElseIf groupNumber = "501" And (numberOfUnits >= 100 And numberOfUnits >= 0) Then
            unitPrice = 59.99

        ElseIf groupNumber = "062" And (numberOfUnits < 100 And numberOfUnits >= 0) Then
            unitPrice = 109.99

        ElseIf groupNumber = "062" And (numberOfUnits >= 100 And numberOfUnits >= 0) Then
            unitPrice = 67.99
        End If



    End Sub
 
Back
Top