Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple conditions with Select Case in VB 2010

Tags:

vb.net

case

I am trying to figure out how to test two conditions in a Case Statement.

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

I cannot get AND to work, what am I doing wrong?

like image 780
Alli OGrady Avatar asked Dec 13 '22 03:12

Alli OGrady


2 Answers

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

Or maybe this if you want to catch 2.5 as >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
like image 173
Stefan Avatar answered Jan 05 '23 23:01

Stefan


You don't need to check for a weight greater than two in the second Case. If it's not greater than two, then it will have entered the first case. So you can simplify it to this:

Select Case txtWeight.Text
    Case Is <= 2
        decShippingCost = (decShipping2 + (decShipping2 * 0.26))
    Case Is <= 4
        decShippingCost = (decShipping4 + (decShipping4 * 0.026))
End Select
like image 27
Meta-Knight Avatar answered Jan 05 '23 22:01

Meta-Knight