Vb.net 为什么我的Select案例不起作用

Vb.net 为什么我的Select案例不起作用,vb.net,select,case,Vb.net,Select,Case,好的,我的问题如下;我想我把所有的东西都编好了,在我做选择的时候,我希望前三种口味只花55美分,但是当我做我的代码的时候,不管我选择什么类型的冰淇淋,它总是让勺子花65美分,我不知道如何改变它,我以为我做对了,但它不起作用 Public Class frmJoeyIceCreamParlour Const MIN_SCOOPS = 1 Const MAX_SCOOPS = 9 Const BASIC_FLAVOUR = 0.55 Const PREMIUM_FLA

好的,我的问题如下;我想我把所有的东西都编好了,在我做选择的时候,我希望前三种口味只花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
公共级frmjoeyicream会客厅
Const MIN_SCOOPS=1
Const MAX_SCOOPS=9
常量基本值=0.55
Const PREMIUM_flavor=0.65
常数顶部=0.6
常数DEEZ_螺母=0.5
常量搅打奶油=0.65
作为单身的公共公寓
公共scoopType为双精度
公共运行总计为双倍
私有子frmjoeyicetreampallour_Load(发送方作为对象,e作为事件参数)处理MyBase.Load
添加“香草”香精
添加(“巧克力”)
添加“草莓”口味。项目
lstFlavors.项目。添加(“芒果”)
lstFlavors.Items.Add(“班纳纳”)
添加(“葡萄”)
添加(“薄荷巧克力片”)
端接头
私有子btnCalculate\u单击(发送者作为对象,e作为事件参数)处理btnCalculate。单击
如果txtScoops.Text=Nothing,则
Show(“请在scoops类别中输入一个值。”)
txtScoops.Focus()
如果不是数字(txtScoops.Text),则
MessageBox.Show(“输入必须是数字!请重试。”)
txtScoops.Focus()
ElseIf txtScoops.TextMAX\u SCOOPS然后
Show(“请输入一个介于1到9个勺子之间的数字。”)
txtScoops.Focus()
ElseIf lstFlavors.SelectedItem=然后什么都没有
MessageBox.Show(“请选择一种口味”)
ElseIf rdoNoTopping.Checked=False和rdoOneTopping.Checked=False和rdoTwoTopping.Checked=False和rdothretopping.Checked=False然后
MessageBox.Show(“请选择您想要的配料量。”)
其他的
整数形式的数字=7
选择案例编号
案例1至3
scoopType=基本口味
案例4至7
scoopType=高级风味
runningTotal=scoopType*Double.Parse(txtScoops.Text)
结束选择
如果rdoOneTopping.Checked=True,则
runningTotal=runningTotal+浇头
ElseIf rdoTwoTopping.Checked=True然后
runningTotal=runningTotal+(排名第一*2)
ElseIf rdothretopping.Checked=True然后
runningTotal=runningTotal+(排名第一*3)
如果结束
如果chkWhippedCream.Checked=True,则
runningTotal=runningTotal+搅打奶油
如果结束
如果chkNuts.Checked=真,则
runningTotal=runningTotal+DEEZ_螺母
如果结束
lblOutputTotal.Text=(FormatCurrency(runningTotal))
如果结束
端接头
末级

您已通过
选择案例编号
语句上方的行对使用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)

好吧,我按照你的要求做了,现在前3个显示为0.00美元,其他显示为0.65美元,你有解决方案吗@travisYea,将
runningTotal=scoopType*Double.Parse(txtScoops.Text)
片段移出select语句。正如目前编写的,只有4到7个案例符合该代码。我会用一个完整的例子来更新我的答案,这两个改变,等一下。欢迎来到stackoverflow。请阅读。提示:尝试使用导致问题的紧凑、最小的代码段。如果问题在所选案例中,我们不需要孔方法代码……然后当您得到答案时,单击其中一个旁边的复选标记表示感谢。