Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Select Case statement
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 02 May 2002 :  02:19:01  Show Profile
I am doing a loop through some records. And in that loop, I check the percentage of how many records it has processed using a Select Case statement.
for counter = 0 to TotalRecs
Select Case FormatNumber(counter/TotalRecs*100,0)
Case 10
   Response.Write "."
Case 20
   Response.Write "."
Case ...
   ...
End Select
next
Now I want each Case execute depending on the range. So if the percentage is less than 10, execute that case. But somehow how I can't get a range using the select statement. I have tried the following variations but it won't work, just gives me an error:
Case 1 To 10
   Response.Write "."
Case 11 To 20
   Response.Write "."
....
Case Is < 10
   Response.Write "."
Case Is < 20
   Response.Write "."
...
The only thing that works is this:
Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
   Response.Write "."
Case 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
   Response.Write "."
...
Anyone know if it is possible to do a range using the select statement?

«------------------------------------------------------»
Want to know when the next version comes out,
as soon as possible? Join our Mailing Lists !

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 02 May 2002 :  02:25:09  Show Profile
Nevermind, I'll use an if else statement instead.

«------------------------------------------------------»
Want to know when the next version comes out,
as soon as possible? Join our Mailing Lists !
Go to Top of Page

Nathan
Help Moderator

USA
7664 Posts

Posted - 02 May 2002 :  02:31:05  Show Profile  Visit Nathan's Homepage
for counter = 0 to TotalRecs
Select Case FormatNumber(counter/TotalRecs*10,0)
Case 1
Response.Write "."
Case 2
Response.Write "."
End Select
next

Nathan Bales
Snitz Exchange | Do's and Dont's
Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 03 May 2002 :  21:19:22  Show Profile
Try this...


dim intMyVar
for counter = 0 to TotalRecs
intMyVar = FormatNumber(counter/TotalRecs*100,0)
Select Case TRUE
Case (intMyVar <= 10)
    Response.Write "."
Case (intMyVar <= 20)
    Response.Write "."
Case ...
    ...
End Select
next


With Select Case in VBScript, once it hits a case where it's TRUE, then it executes whatever code is there and then drops out of the select statement.

If you had something like 10.1, that would not make the first case true, but would make the second case true. So if you wanted to reuse that % value in your code, but wanted to display the 1,2 or more decimal positions, you could set FormatNumber(counter/TotalRecs*100,2) one time and use it for your select statement and any code inside that case.

If you wanted to have 10.1, but wanted to include anything under 11 as part of the first case, then just look for everything < 11.

Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 03 May 2002 :  23:01:26  Show Profile
quote:

Nevermind, I'll use an if else statement instead.



Select Case is more efficient.

I'd say always, but someone would probably come and give an instance when it's not so I won't.

Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 04 May 2002 :  10:07:00  Show Profile
Thanks Workmule.
And Nathan.

I agree with you that a Select Case would be more efficient. But that's just our opinion.

«------------------------------------------------------»
Want to know when the next version comes out,
as soon as possible? Join our Mailing Lists !
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 04 May 2002 :  12:37:33  Show Profile
Select Case is usually a little faster than If Then because the expression is only evaluated once.

But when you use the syntax above, you're still evaluating an expression on each test, so I'll go out on a limb and guess that in the select case above there would be no difference in execution speed over an If Then


======
Doug G
======
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.32 seconds. Powered By: Snitz Forums 2000 Version 3.4.07