Select Case Is

emia
08-15-2009, 06:19 AM
Hello, Would you mind help me this:
I need
PRICE < xMin, return = 5
PRICE between xMin To xMax , return PRICE
PRICE > xMax , return = 100

but no success ? , I think is "Case IS" or "Case" , right?

Any idea please!


Private Sub Command1_Click()



xSub = Text1.Text
xPer = "0.005"
xMin = "5"
xMax = "100"

v_VOL = (xSub) * (xPer) / 100

Select Case v_VOL:

Case Is < xMin
v_RET = xMin

Case xMin To xMin
v_RET = v_VOL


Case Is > xMax
v_RET = xMax

End Select


Debug.Print Time, "price=" & v_VOL & ";because between " & xMin & "to" & xMax & ", retn " & v_RET


End Sub

Burningslash12
08-15-2009, 10:11 AM
Hi! Here is a sample code:


Sub test()

price = 25

xmin = 5
xmax = 100

Select Case price

Case Is < xmin
myReturn = xmin
Case Is > xmax
myReturn = xmax
Case Else 'from xmin to xmax
myReturn = price
End Select

Debug.Print myReturn

End Sub



Take note that in my sample code, i remove the quotes in xmin and xmax, so these 2 variables will become numbers and not string. This is where you missed it in your code. You are comparing a string and a number.

Another thing is, for the code below:

xSub = Text1.Text
xPer = "0.005"
xMin = "5"
xMax = "100"

v_VOL = (xSub) * (xPer) / 100



What is the range of values for xSub? Is it in the range of 100000 or more? If not, your result will always be less than 5.

Hope this helps.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum