|
-
Feb 23rd, 2013, 03:16 PM
#1
Thread Starter
New Member
Need help with radio buttons within a select case.
I have to write a program that uses radio buttons to apply a discount to the subtotal. This has to be done with select case. Also, all the discount amounts have to be constants. I have tried many different ways, but after 2 days i give up.
Public Class Form1
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtCoffee.Text = "0"
txtEspresso.Text = "0"
rad0.Checked = True
rad10.Checked = False
rad25.Checked = False
rad50.Checked = False
lblSubtotal.Text = ""
lblTax.Text = ""
lblTotal.Text = ""
End Sub
Private Sub btnCheckout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckout.Click
Const CONSTCOFFEE As Decimal = CDec(1.95)
Const CONSTESPRESSO As Decimal = CDec(3.95)
Const CONSTTAX As Decimal = CDec(0.07)
Const CONSTDISC0 As Decimal = CDec(0)
Const CONSTDISC10 As Decimal = CDec(0.1)
Const CONSTDISC25 As Decimal = CDec(0.25)
Const CONSTDISC50 As Decimal = CDec(0.5)
Dim intCoffee As Integer = 0
Dim intEspresso As Integer = 0
intCoffee = CInt(txtCoffee.Text)
intEspresso = CInt(txtEspresso.Text)
Dim decSubtotal As Decimal = 0
Dim decTax As Decimal = 0
Dim decTotal As Decimal = 0
Dim decDiscount As Decimal = 0
Dim decPreSubDisc As Decimal = 0
Dim decCalculation As Decimal = 0
Dim decCoffee As Decimal
Dim decEspresso As Decimal
If Decimal.TryParse(txtCoffee.Text, decCoffee) Then
If Decimal.TryParse(txtEspresso.Text, decEspresso) Then
MessageBox.Show("You have ordered " & txtCoffee.Text & " coffee(s)" & ControlChars.CrLf & txtEspresso.Text & " espresso(s).")
Select Case CDec(decDiscount)
Case 1
If rad0.Checked = True Then
decDiscount = CONSTDISC0
End If
Case 2
If rad10.Checked = True Then
decDiscount = CONSTDISC10
End If
Case 3
If rad10.Checked = True Then
decDiscount = CONSTDISC25
End If
Case 4
If rad10.Checked = True Then
decDiscount = CONSTDISC50
End If
End Select
decPreSubDisc = CDec((CONSTCOFFEE * intCoffee) + (CONSTESPRESSO * intEspresso))
decSubtotal = CDec(decPreSubDisc - (((CONSTCOFFEE * intCoffee) + (CONSTESPRESSO * intEspresso)) * decDiscount))
lblSubtotal.Text = decSubtotal.ToString("c")
decTax = CDec(decSubtotal * CONSTTAX)
lblTax.Text = decTax.ToString("c")
decTotal = CDec(decSubtotal + decTax)
lblTotal.Text = decTotal.ToString("c")
End If
Else : MessageBox.Show("Please enter numbers only")
txtCoffee.Text = "0"
txtEspresso.Text = "0"
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|