为什么我的Select Case无效

时间:2015-05-10 02:53:56

标签: vb.net select case

好的,我的问题如下:我认为我编写了一切正确的execpt我做我的选择案例的部分,我希望前3个Flavors只花费55美分但是当我做我的代码它总是使勺子65美分无论我选择什么冰淇淋类型和我不知道如何让它改变,我以为我做得对,但它没有工作

Public Class frmJoeyIceCreamParlour
    Const MIN_SCOOPS = 1
    Const MAX_SCOOPS = 9
    Const BASIC_FLAVOUR = 0.55
    Const PREMIUM_FLAVOUR = 0.65
    Const TOPPING = 0.6
    Const DEEZ_NUTS = 0.5
    Const WHIPPED_CREAM = 0.65
    Public scoopEntry As Single
    Public scoopType As Double
    Public runningTotal As Double

    Private Sub frmJoeyIceCreamParlour_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lstFlavours.Items.Add("Vanilla")
        lstFlavours.Items.Add("Chocolate")
        lstFlavours.Items.Add("Strawberry")
        lstFlavours.Items.Add("Mango")
        lstFlavours.Items.Add("Bananna")
        lstFlavours.Items.Add("Grape")
        lstFlavours.Items.Add("Mint Chocolate Chip")
    End Sub

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        If txtScoops.Text = Nothing Then
            MessageBox.Show("Please enter a value in the scoops category.")
            txtScoops.Focus()

        ElseIf Not IsNumeric(txtScoops.Text) Then
            MessageBox.Show("Entry must be numeric! Please try again.")
            txtScoops.Focus()

        ElseIf txtScoops.Text < MIN_SCOOPS Or txtScoops.Text > MAX_SCOOPS Then
            MessageBox.Show("Please enter a number between 1 and 9 scoops.")
            txtScoops.Focus()

        ElseIf lstFlavours.SelectedItem = Nothing Then
            MessageBox.Show("Please select a flavour.")

        ElseIf rdoNoTopping.Checked = False And rdoOneTopping.Checked = False And rdoTwoTopping.Checked = False And rdoThreeTopping.Checked = False Then
            MessageBox.Show("Please select the amount of toppings you would like.")

        Else
            Dim number As Integer = 7
            Select Case number

                Case 1 To 3
                    scoopType = BASIC_FLAVOUR
                Case 4 To 7
                    scoopType = PREMIUM_FLAVOUR

                    runningTotal = scoopType * Double.Parse(txtScoops.Text)
            End Select

            If rdoOneTopping.Checked = True Then
                runningTotal = runningTotal + TOPPING

            ElseIf rdoTwoTopping.Checked = True Then
                runningTotal = runningTotal + (TOPPING * 2)

            ElseIf rdoThreeTopping.Checked = True Then
                runningTotal = runningTotal + (TOPPING * 3)

            End If

            If chkWhippedCream.Checked = True Then
                runningTotal = runningTotal + WHIPPED_CREAM

             End If

            If chkNuts.Checked = True Then
                runningTotal = runningTotal + DEEZ_NUTS

            End If
            lblOutputTotal.Text = (FormatCurrency(runningTotal))
        End If
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

您已经硬编码通过Select case number声明正上方的行使用7:Dim number As Integer = 7。您应该通过执行Dim number As Integer = lstFlavours.SelectedIndex

之类的操作来查找所选索引
Dim number As Integer = lstFlavours.SelectedIndex
Select Case number

    Case 1 To 3
        scoopType = BASIC_FLAVOUR
    Case 4 To 7
        scoopType = PREMIUM_FLAVOUR
End Select

runningTotal = scoopType * Double.Parse(txtScoops.Text)