Can someone look at this code and tell me why I am getting errors and warnings. I have everything just like the book says but it doesn't work. Here is the code:

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Class-level declarations
Const decTAX_RATE As Decimal = 0.06D ' Tax rate
Const decWHITE_BAGEL As Decimal = 1.25D ' Cost of a white bagel
Const decWHEAT_BAGEL As Decimal = 1.5D ' Cost of a wheat bagel
Const decCREAM_CHEESE As Decimal = 0.5D ' Cost of cream cheese topping
Const decBUTTER As Decimal = 0.25D ' Cost of butter topping
Const decBLUEBERRY As Decimal = 0.75D ' Cost of blueberry topping
Const decRASPBERRY As Decimal = 0.75D ' Cost of raspberry topping
Const decPEACH As Decimal = 0.75D ' Cost of peach topping
Const decREG_COFFEE As Decimal = 1.25D ' Cost of regular coffee
Const decCAPPUCCINO As Decimal = 2D ' Cost of cappuccino
Const decCAFE_AU_LAIT As Decimal = 1.75D ' Cost of cafe au lait

End Sub

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

decSubtotal = BagelCost() + ToppingCost() + CoffeeCost()
decTax = CalcTax(decSubtotal)
decTotal = decSubtotal + decTax

lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c")

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
' This procedure resets the controls to default values.
ResetBagels()
ResetToppings()
ResetCoffee()
ResetPrice()

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' Close the form
Me.Close()

End Sub
End Class

Function BagelCost() As Decimal
' This function returns the cost of the selected bagel.
Dim decBagel As Decimal

If RadWhite.Checked = True Then
decBagel = decWHITE_BAGEL()
Else
decBagel = decWHEAT_BAGEL()
End If

Return decBagel
End Function
Function ToppingCost() As Decimal
' this function returns the cost of the toppings.
Dim decCostOfTopping As Decimal = OD

If chkCreamCheese.Checked = True Then
decCostOfTopping += decCREAM_CHEESE
End If

If chkButter.Checked = True Then
decCostOfTopping += decBUTTER
End If

If chkBlueberry.Checked = True Then
decCostOfTopping += decBLUEBERRY
End If

If chkRaspberry.Checked = True Then
decCostOfTopping += decRASPBERRY
End If

If chkPeach.Checked = True Then
decCostOfTopping += decPEACH
End If

Return decCostOfTopping
End Function

Function CoffeeCost() As Decimal
' This function returns the cost of the selected coffee.
Dim decCoffee As Decimal

If Radnocoffee.Checked Then
decCoffee = OD
ElseIf RadRegCoffee.Checked = True Then
decCoffee = decREG_COFFEE
ElseIf RadCappuccino.Checked = True Then
decCoffee = decCAPPUCCINO
ElseIf RadCafeAuLait.Checked = True Then
decCoffee = decCAFE_AU_LAIT()

End If

Return decCoffee
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

Sub ResetBagels()
' This procedure resets the bagel selection.
RadWhite.Checked = True
End Sub

Sub ResetToppings()
' This procedure resets the topping selection.
chkCreamCheese.Checked = False
chkButter.Checked = False
chkBlueberry.Checked = False
chkRaspberry.Checked = False
chkPeach.Checked = False
End Sub

Sub ResetCoffee()
' this procedure resets the coffee selection.
RadRegCoffee.Checked = True

End Sub

Sub ResetPrice()
'This procedure resets the price.
lblSubtotal.Text = String.Empty
lblTax.Text = String.Empty
lblTotal.Text = String.Empty
End Sub

Recommended Answers

All 3 Replies

Can you post the errors you are getting?

Errors are unused local constant:'decTAX_RATE'.
one error for each of the 11 listed

Class

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

decSubtotal = BagelCost() + ToppingCost() + CoffeeCost()
decTax = CalcTax(decSubtotal)
decTotal = decSubtotal + decTax

lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c")

End Sub

identifier expected error on class in this segment

Member Avatar for Unhnd_Exception

You have your constants defined in the load event!

Move them out of there place them here:

Public Class Form1

Const decTAX_RATE As Decimal = 0.06D ' Tax rate
Const decWHITE_BAGEL As Decimal = 1.25D ' Cost of a white bagel
Const decWHEAT_BAGEL As Decimal = 1.5D ' Cost of a wheat bagel
Const decCREAM_CHEESE As Decimal = 0.5D ' Cost of cream cheese topping
Const decBUTTER As Decimal = 0.25D ' Cost of butter topping
Const decBLUEBERRY As Decimal = 0.75D ' Cost of blueberry topping
Const decRASPBERRY As Decimal = 0.75D ' Cost of raspberry topping
Const decPEACH As Decimal = 0.75D ' Cost of peach topping
Const decREG_COFFEE As Decimal = 1.25D ' Cost of regular coffee
Const decCAPPUCCINO As Decimal = 2D ' Cost of cappuccino
Const decCAFE_AU_LAIT As Decimal = 1.75D ' Cost of cafe au lait

Delete the form load event as you have nothing in there of interest

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.