我试图弄清楚如何在案例陈述中测试两个条件。
Select Case txtWeight.Text
Case Is <= 2
decShippingCost = (decShipping2 + (decShipping2 * 0.26))
Case Is > 2 and <= 4
decShippingCost = (decShipping4 + (decShipping4 * 0.026))
我无法让AND工作,我做错了什么?
答案 0 :(得分:7)
Select Case txtWeight.Text
Case Is <= 2
decShippingCost = (decShipping2 + (decShipping2 * 0.26))
Case 3 to 4
decShippingCost = (decShipping4 + (decShipping4 * 0.026))
End Select
或许这可能是你想要将2.5作为&gt; 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
答案 1 :(得分: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