VBScript Select Case vs VB Select Case 
Author Message
 VBScript Select Case vs VB Select Case

Hi there,

I'm stuck with a simple select case statement in VBScript
(ASP). The situation is like this :

SELECT CASE iNumber
   CASE 0 : 'code works fine here
   CASE 1,2,3 : 'this also works fine
   CASE 4 to 90 : 'this doesn't work (does in VB, not ASP)
   CASE Is < 152 : 'doesn't work in ASP, does work in VB
END SELECT

What's happening here?

So, i need to check iNumber vs a specific range, but it
will only work when I use a comma delimited list. The IS
operator or the TO don't seem to work in VBSCRIPT like in
VB. Is there another syntax that has to be used here?

Can someone help me out?

Thanx, Bart



Thu, 21 Apr 2005 21:46:05 GMT  
 VBScript Select Case vs VB Select Case

Quote:

> Hi there,

> I'm stuck with a simple select case statement in vbscript
> (ASP). The situation is like this :

> SELECT CASE iNumber
[...]
>   CASE 4 to 90 : 'this doesn't work (does in VB, not ASP)
>   CASE Is < 152 : 'doesn't work in ASP, does work in VB

You are, indeed, correct. To be precise, however, ASP is irrelevant -
the syntax does not work in VBScript, period. For future reference this,
and other differences, are listed at
<http://msdn.microsoft.com/library/en-us/script56/html/vsgrpnonfeature...>.

There is not a direct replacement for the syntax, but you can use a
useful kludge courtesy of Michael Harris:

Select Case True
  ...
  Case iNumber >= 4 And iNumber <= 90
    'Do stuff
  Case iNumber < 152
    'Do other stuff
End Select

hth

Adam
--
Linux: The OS people choose without $200,000,000 of persuasion.
        -- Mike Coleman



Thu, 21 Apr 2005 22:16:57 GMT  
 VBScript Select Case vs VB Select Case



Quote:

> > Hi there,

> > I'm stuck with a simple select case statement in vbscript
> > (ASP). The situation is like this :

> > SELECT CASE iNumber
> [...]
> >   CASE 4 to 90 : 'this doesn't work (does in VB, not ASP)
> >   CASE Is < 152 : 'doesn't work in ASP, does work in VB

> You are, indeed, correct. To be precise, however, ASP is irrelevant -
> the syntax does not work in VBScript, period. For future reference this,
> and other differences, are listed at

<http://msdn.microsoft.com/library/en-us/script56/html/vsgrpnonfeature...>
.

Quote:

> There is not a direct replacement for the syntax, but you can use a
> useful kludge courtesy of Michael Harris:

> Select Case True
>   ...
>   Case iNumber >= 4 And iNumber <= 90
>     'Do stuff
>   Case iNumber < 152
>     'Do other stuff
> End Select

> hth

> Adam
> --
> Linux: The OS people choose without $200,000,000 of persuasion.
>         -- Mike Coleman

Indeed, it works fine like that! I was looking everywhere for another
syntax, but this is a nice solution I didn't think of. Thanks alot for the
help, Adam...


Thu, 21 Apr 2005 22:20:14 GMT  
 VBScript Select Case vs VB Select Case
A logical expression works well as a generic fix, also...

Select Case True
Case x<4
Case x<90
Case x<152
Case Else
End Select

The key thing I've found useful to the logical expression approach is it seems
to be easier to abstract.


Adam D. Barratt typed:

Quote:

>> Hi there,

>> I'm stuck with a simple select case statement in vbscript
>> (ASP). The situation is like this :

>> SELECT CASE iNumber
> [...]
>>   CASE 4 to 90 : 'this doesn't work (does in VB, not ASP)
>>   CASE Is < 152 : 'doesn't work in ASP, does work in VB

> You are, indeed, correct. To be precise, however, ASP is irrelevant -
> the syntax does not work in VBScript, period. For future reference
> this, and other differences, are listed at
> <http://msdn.microsoft.com/library/en-us/script56/html/vsgrpnonfeature...>.

> There is not a direct replacement for the syntax, but you can use a
> useful kludge courtesy of Michael Harris:

> Select Case True
>   ...
>   Case iNumber >= 4 And iNumber <= 90
>     'Do stuff
>   Case iNumber < 152
>     'Do other stuff
> End Select

> hth

> Adam

--
Please respond in the newsgroup so everyone may benefit.
 http://dev.remotenetworktechnology.com
 ----------
 Subscribe to Microsoft's Security Bulletins:
 http://www.microsoft.com/technet/security/bulletin/notify.asp


Fri, 22 Apr 2005 16:19:32 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. "select...case", multiples cases not possible ?

2. Select Case and Case 0 To 9

3. Case Select vs If then Else

4. Select Case Vs If - ElseIf

5. If..Elseif vs. Select case

6. Select Case in VB Script

7. Select Case statement in VBScript

8. Is the Select Case Statement crippled in VBScript?

9. VBScript Dynamic Select Case

10. Using Select Case in VBScript

11. Select case in vbscript

12. select case in VB

 

 
Powered by phpBB® Forum Software