选择案例不起作用

时间:2014-04-11 13:34:26

标签: vb.net

   If decItemWeight > 0 Then
        Select Case decShippingPrice
            Case Is <= 2
                decShippingPrice = 3.69D
            Case Is <= 4
                decShippingPrice = 4.86D
            Case Is <= 6
                decShippingPrice = 5.63D
            Case Is <= 8
                decShippingPrice = 5.98D
            Case Is <= 10
                decShippingPrice = 6.28D
            Case Is <= 30
                decShippingPrice = 15.72D
        End Select
    End If

上面是我正在处理的Visual Basic的代码。当我输入一个大于2的值时,价格应该大于3.69美元的初始值。但是,程序似乎只运行第一种情况。因此,无论我输入的值如何,屏幕上将始终打印$ 3.69。关于如何解决错误的任何想法。

1 个答案:

答案 0 :(得分:2)

您正在与错误的变量进行比较。请改用decItemWeight:

If decItemWeight > 0 Then
    Select Case decItemWeight 
        Case Is <= 2
            decShippingPrice = 3.69D
        Case Is <= 4
           decShippingPrice = 4.86D
        Case Is <= 6
            decShippingPrice = 5.63D
        Case Is <= 8
            decShippingPrice = 5.98D
        Case Is <= 10
            decShippingPrice = 6.28D
        Case Is <= 30
            decShippingPrice = 15.72D
    End Select
End If