VBS equivilent to JScript 'switch' statement 
Author Message
 VBS equivilent to JScript 'switch' statement

I'm looking for a VBS function that is equivilent to JScript 'switch'
statement, or do I have to build a Do...While loop and work from scratch?


Wed, 23 Jun 2004 12:00:25 GMT  
 VBS equivilent to JScript 'switch' statement
switch's vbs version is select-case. e.g.

select case x
    case 1
        do something
    case 2
        do something
    case else
        do something
end select

I don't know JScript, but in C case there should be 'break;' for each 'case'
if you don't want to go next case. Not needed in VBS.


Quote:
> I'm looking for a VBS function that is equivilent to JScript 'switch'
> statement, or do I have to build a Do...While loop and work from scratch?



Wed, 23 Jun 2004 12:39:36 GMT  
 VBS equivilent to JScript 'switch' statement
There-in lies the hook. The C++/JScript versions will fall through and
process subsequent statements if there is not a [break] statement. The VB(S)
Select Case statement stops when it has found the first match. I'm looking
for something that will continue processing, like the Switch statement.


Quote:
> switch's vbs version is select-case. e.g.

> select case x
>     case 1
>         do something
>     case 2
>         do something
>     case else
>         do something
> end select

> I don't know JScript, but in C case there should be 'break;' for each
'case'
> if you don't want to go next case. Not needed in VBS.



> > I'm looking for a VBS function that is equivilent to JScript 'switch'
> > statement, or do I have to build a Do...While loop and work from
scratch?



Wed, 23 Jun 2004 13:16:36 GMT  
 VBS equivilent to JScript 'switch' statement
That's what you want!
No way AFAIK in vbs, except,

if x=1 then do something
if x=2 then do
if x=3 then do, ...

I hope someone could help you with more elegant way.


Quote:
> There-in lies the hook. The C++/JScript versions will fall through and
> process subsequent statements if there is not a [break] statement. The
VB(S)
> Select Case statement stops when it has found the first match. I'm looking
> for something that will continue processing, like the Switch statement.



> > switch's vbs version is select-case. e.g.

> > select case x
> >     case 1
> >         do something
> >     case 2
> >         do something
> >     case else
> >         do something
> > end select

> > I don't know JScript, but in C case there should be 'break;' for each
> 'case'
> > if you don't want to go next case. Not needed in VBS.



> > > I'm looking for a VBS function that is equivilent to JScript 'switch'
> > > statement, or do I have to build a Do...While loop and work from
> scratch?



Wed, 23 Jun 2004 13:25:20 GMT  
 VBS equivilent to JScript 'switch' statement
Quote:
> I hope someone could help you with more elegant way.

With switch, but using GOTO's :))

Seriously, it's bad coding practice to let the code 'roll on' after the
case. Hard to debug, and hard to maintain. So make the common code outside
of the case statements.

Mike


Quote:
> That's what you want!
> No way AFAIK in vbs, except,

> if x=1 then do something
> if x=2 then do
> if x=3 then do, ...

> I hope someone could help you with more elegant way.



> > There-in lies the hook. The C++/JScript versions will fall through and
> > process subsequent statements if there is not a [break] statement. The
> VB(S)
> > Select Case statement stops when it has found the first match. I'm
looking
> > for something that will continue processing, like the Switch statement.



> > > switch's vbs version is select-case. e.g.

> > > select case x
> > >     case 1
> > >         do something
> > >     case 2
> > >         do something
> > >     case else
> > >         do something
> > > end select

> > > I don't know JScript, but in C case there should be 'break;' for each
> > 'case'
> > > if you don't want to go next case. Not needed in VBS.



> > > > I'm looking for a VBS function that is equivilent to JScript
'switch'
> > > > statement, or do I have to build a Do...While loop and work from
> > scratch?



Fri, 25 Jun 2004 17:58:12 GMT  
 VBS equivilent to JScript 'switch' statement
In addition, if the same code needs to be executed with multiple cases, use
this:

    Case 1,2 ' multiple check
          'code here

Mike


Quote:
> > I hope someone could help you with more elegant way.
> With switch, but using GOTO's :))

> Seriously, it's bad coding practice to let the code 'roll on' after the
> case. Hard to debug, and hard to maintain. So make the common code outside
> of the case statements.

> Mike



> > That's what you want!
> > No way AFAIK in vbs, except,

> > if x=1 then do something
> > if x=2 then do
> > if x=3 then do, ...

> > I hope someone could help you with more elegant way.



> > > There-in lies the hook. The C++/JScript versions will fall through and
> > > process subsequent statements if there is not a [break] statement. The
> > VB(S)
> > > Select Case statement stops when it has found the first match. I'm
> looking
> > > for something that will continue processing, like the Switch
statement.



> > > > switch's vbs version is select-case. e.g.

> > > > select case x
> > > >     case 1
> > > >         do something
> > > >     case 2
> > > >         do something
> > > >     case else
> > > >         do something
> > > > end select

> > > > I don't know JScript, but in C case there should be 'break;' for
each
> > > 'case'
> > > > if you don't want to go next case. Not needed in VBS.



> > > > > I'm looking for a VBS function that is equivilent to JScript
> 'switch'
> > > > > statement, or do I have to build a Do...While loop and work from
> > > scratch?



Fri, 25 Jun 2004 20:48:59 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Switch statement won't work! (JS/ASP)

2. can't debug jscript: source code not available for current statement

3. Invalid 'Exit' Statement

4. Problem Querying with 'Like' Statement

5. SQL 'Like' statement problem

6. Access equivilent of FoxPro's fopen()

7. HELP vbs capture of 'backspace'

8. 'CDONTS.NewMail' and vbs

9. MTS Message...Choose 'Switch To'

10. Jscript runtime error 'c00ce505'

11. Microsoft JScript runtime error '800a01ad'

12. JScript equivalent to 'Option Explicit'?

 

 
Powered by phpBB® Forum Software