Can this be converted to a CASE Statement? 
Author Message
 Can this be converted to a CASE Statement?

     <%
     If arForums(cFORUM_STATUSID, theROWS) <> 1 Then
     %>

     <%
     ElseIf intPlayerType < arForums(cACCESS_LVL, theROWS) Then
     %>

     <%
     ElseIf arForums(cISMEMBER, theROWS) = 0 AND arForums(cTYPEID, theROWS)
= 6 Then
     %>

     <%
     ElseIf arForums(cISMEMBER, theROWS) = 0 Then
     %>

     <%
     Else
     %>

     <%
     End If
     %>



Thu, 02 Dec 2004 12:11:45 GMT  
 Can this be converted to a CASE Statement?
Select Case True
 Case arForums(cFORUM_STATUSID, theROWS) <> 1
Case intPlayerType < arForums(cACCESS_LVL, theROWS)
Case arForums(cISMEMBER, theROWS) = 0 AND arForums(cTYPEID, theROWS)
Case  arForums(cISMEMBER, theROWS) = 0
Case Else
End Select

I think that should do it; may need some grouping in the 3rd statement.


Quote:
>      <%
>      If arForums(cFORUM_STATUSID, theROWS) <> 1 Then
>      %>

>      <%
>      ElseIf intPlayerType < arForums(cACCESS_LVL, theROWS) Then
>      %>

>      <%
>      ElseIf arForums(cISMEMBER, theROWS) = 0 AND arForums(cTYPEID, theROWS)
> = 6 Then
>      %>

>      <%
>      ElseIf arForums(cISMEMBER, theROWS) = 0 Then
>      %>

>      <%
>      Else
>      %>

>      <%
>      End If
>      %>



Thu, 02 Dec 2004 12:37:24 GMT  
 Can this be converted to a CASE Statement?
Okay, thanks, this gives me something to play with ... this extra "depth" to
select statements is still new territory to me.



Quote:
> Select Case True
>  Case arForums(cFORUM_STATUSID, theROWS) <> 1
> Case intPlayerType < arForums(cACCESS_LVL, theROWS)
> Case arForums(cISMEMBER, theROWS) = 0 AND arForums(cTYPEID, theROWS)
> Case  arForums(cISMEMBER, theROWS) = 0
> Case Else
> End Select

> I think that should do it; may need some grouping in the 3rd statement.



> >      <%
> >      If arForums(cFORUM_STATUSID, theROWS) <> 1 Then
> >      %>

> >      <%
> >      ElseIf intPlayerType < arForums(cACCESS_LVL, theROWS) Then
> >      %>

> >      <%
> >      ElseIf arForums(cISMEMBER, theROWS) = 0 AND arForums(cTYPEID,
theROWS)
> > = 6 Then
> >      %>

> >      <%
> >      ElseIf arForums(cISMEMBER, theROWS) = 0 Then
> >      %>

> >      <%
> >      Else
> >      %>

> >      <%
> >      End If
> >      %>



Thu, 02 Dec 2004 12:49:00 GMT  
 Can this be converted to a CASE Statement?
Sure, but it doesn't seem any better (meaning easier to read/maintain) to me ;-)...

<%
Select Case True
  Case CBool(arForums(cFORUM_STATUSID, theROWS) <> 1)
%>

<%
  Case CBool(intPlayerType < arForums(cACCESS_LVL, theROWS))
%>

<%
  Case CBool((arForums(cISMEMBER, theROWS) = 0) AND _
            (arForums(cTYPEID, theROWS)= 6))
%>

<%
  Case CBool(arForums(cISMEMBER, theROWS) = 0)
%>

<%
  Case Else
%>

<%
End Select
%>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 02 Dec 2004 12:58:08 GMT  
 Can this be converted to a CASE Statement?
So as a rule of thumb, CASE statements are not 'better'? Read: Offer
performance improvements?



Sure, but it doesn't seem any better (meaning easier to read/maintain) to me
;-)...

<%
Select Case True
  Case CBool(arForums(cFORUM_STATUSID, theROWS) <> 1)
%>

<%
  Case CBool(intPlayerType < arForums(cACCESS_LVL, theROWS))
%>

<%
  Case CBool((arForums(cISMEMBER, theROWS) = 0) AND _
            (arForums(cTYPEID, theROWS)= 6))
%>

<%
  Case CBool(arForums(cISMEMBER, theROWS) = 0)
%>

<%
  Case Else
%>

<%
End Select
%>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 02 Dec 2004 22:28:39 GMT  
 Can this be converted to a CASE Statement?
:: So as a rule of thumb, CASE statements are not 'better'? Read: Offer
:: performance improvements?
::

I wouldn't be surprised (at least in the VB/VBA/VBScript family) if the 'Select Case...End Select' and 'If...ElseIf...End If' constructs both generate nearly identical machine code at runtime in this particular scenario.  Either construct can be semi-optimized by putting the conditional tests in most likely to least likely order wherever possible.

If Eric Lippert or Mike Whalen happen to wander by, they could give a more definitive view on performance difference of the constructs themselves (if any).

IMHO 'Faster' does not always imply 'Better' if the faster construct is significantly more difficult for a programmer to understand.  Besides, if performance is a high priority then scripting is probably not the right solution.  

I would venture a guess that in most cases the overhead of the many COM objects manipulated by the script will make the CPU cycles used by the script code that glues it all together an insignificant blip on the radar screen ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Fri, 03 Dec 2004 01:43:01 GMT  
 Can this be converted to a CASE Statement?
Gotcha, that makes sense.



:: So as a rule of thumb, CASE statements are not 'better'? Read: Offer
:: performance improvements?
::

I wouldn't be surprised (at least in the VB/VBA/VBScript family) if the
'Select Case...End Select' and 'If...ElseIf...End If' constructs both
generate nearly identical machine code at runtime in this particular
scenario.  Either construct can be semi-optimized by putting the conditional
tests in most likely to least likely order wherever possible.

If Eric Lippert or Mike Whalen happen to wander by, they could give a more
definitive view on performance difference of the constructs themselves (if
any).

IMHO 'Faster' does not always imply 'Better' if the faster construct is
significantly more difficult for a programmer to understand.  Besides, if
performance is a high priority then scripting is probably not the right
solution.

I would venture a guess that in most cases the overhead of the many COM
objects manipulated by the script will make the CPU cycles used by the
script code that glues it all together an insignificant blip on the radar
screen ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Fri, 03 Dec 2004 02:09:35 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Converting a Upper Case String to Upper and Lower Case

2. Case statements in Postscript

3. Select Case statement in VBScript

4. Need Help Using the Case Statement

5. Case Statement based on first letter of an Inputed variable

6. Select Case Statement

7. If statement in select case problem

8. Select Case Statement

9. Select Case Statement

10. If Statement or Case

11. Is the Select Case Statement crippled in VBScript?

12. Problem with Expression in a Select Case Statement

 

 
Powered by phpBB® Forum Software