VB 2010中使用Select Case的多个条件

All*_*ady 4 vb.net case

我试图弄清楚如何在案例陈述中测试两个条件.

Select Case txtWeight.Text
     Case Is <= 2
        decShippingCost = (decShipping2 + (decShipping2 * 0.26))
     Case Is > 2 and <= 4
        decShippingCost = (decShipping4 + (decShipping4 * 0.026))
Run Code Online (Sandbox Code Playgroud)

我无法让AND工作,我做错了什么?

Ste*_*fan 7

Select Case txtWeight.Text
    Case Is <= 2
        decShippingCost = (decShipping2 + (decShipping2 * 0.26))
    Case 3 to 4
        decShippingCost = (decShipping4 + (decShipping4 * 0.026))
End Select
Run Code Online (Sandbox Code Playgroud)

或者这可能是你想要捕获2.5> 2.

Select Case txtWeight.Text
    Case Is <= 2
        decShippingCost = (decShipping2 + (decShipping2 * 0.26))
    Case 2.01 to 4
        decShippingCost = (decShipping4 + (decShipping4 * 0.026))
End Select
Run Code Online (Sandbox Code Playgroud)


Met*_*ght 6

在第二种情况下,您无需检查重量是否大于2.如果它不大于2,那么它将进入第一种情况.所以你可以简化它:

Select Case txtWeight.Text
    Case Is <= 2
        decShippingCost = (decShipping2 + (decShipping2 * 0.26))
    Case Is <= 4
        decShippingCost = (decShipping4 + (decShipping4 * 0.026))
End Select
Run Code Online (Sandbox Code Playgroud)