Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Case Question

Status
Not open for further replies.

Jasonic

Technical User
Jun 20, 2001
69
GB
Everyone

I am trying to use ranges in my select case but with no joy.

I have tried 1..2 also 1.2 and 1-2 e.g.

Select Case myVar
Case 1..2 :
or
Case 1.2 :
or
Case 1-2 :

Basically, I need to run certain code when a value falls between the range of values in the Case statement

Any help appreciated :) Jason Thomas
AssetCenter Consultant
:)
 
Does this work?

Case 1 to 2

without the colon BDC.
 
Thanks BDC2 for your prompt response, but no it doesn work.

I have also tried Case [1..2] without any luck Jason Thomas
AssetCenter Consultant
:)
 
If you don't know the actual values, I think you will have to use an If Then Else statement instead of the Select Case statement.

Select Case will execute statements based on the value of an expression. You can include more than one value, but you cannot evaluate a condition.
Select Case MyVar
Case 1,2 Response.Write(&quot;Value = 1 or 2 <br>&quot;)
Case Else Response.Write(&quot;Value = &quot; & MyVar & &quot; not 1 or 2<br>&quot;)
End Select

If Then Else will execute statements based on the value of a condition:
If MyVar >=1 and MyVar <= 2
Then Response.Write(&quot;Value is between 1 and 2<br>&quot;)
End If

Let me know if this helps.
 
Khazmir

Thanks for your post, I have in fact re-written the case statement into If then else.

I have previously seen the ability to use a range in select case statements......:p

The Code would look better in a select case, but never mind:-( Jason Thomas
AssetCenter Consultant
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top