Jump to content
Macro Express Forums

Multiple IFs vs Case...


Recommended Posts

I'm guessing that MacExp doesn't care whether I use

========================

IF variable %123% = foo

Do this

END IF

IF variable %123% = bar

Do this

END IF

IF variable %123% = zip

Do this

END IF

IF variable %123% = bam

Do this

END IF

========================

or if I use

========================

SWITCH

CASE variable %123% = foo

Do this

END CASE

CASE variable %123% = bar

Do this

END CASE

CASE variable %123% = zip

Do this

END CASE

CASE variable %123% = bam

Do this

END CASE

END SWITCH

========================

 

I haven't actually used the 'Switch' one so I'm not sure if this syntax is correct, but I think it is...

I've looked in Visual Basic books and in VB it looks like the Select Case option is actually more compact than having multiple ifs (i.e. you do the same thing but with fewer lines of code).

 

With MacExp though, it seems that the Case method actually uses *more* lines of code that just using If/End If over and over....

 

Are there other benefits to using "Case" that I'm missing???

 

Thanks. -steve

Link to comment
Share on other sites

I haven't actually used the 'Switch' one so I'm not sure if this syntax is correct, but I think it is...

 

Nearly. The variable goes in the SWITCH and then doesn't need to appear again. Like this:

 

SWITCH variable %123%

CASE = foo

Do this

END CASE

CASE = bar

Do this

END CASE

CASE = zip

Do this

END CASE

CASE = bam

Do this

END CASE

END SWITCH

 

And if you wanted to OR these, it can be done neatly like this:

 

SWITCH variable %123%

CASE = foo

CASE = bar

CASE = zip

CASE = bam

Do this

END CASE

END SWITCH

 

I've looked in Visual Basic books and in VB it looks like the Select Case option is actually more compact than having multiple ifs (i.e. you do the same thing but with fewer lines of code).

 

With MacExp though, it seems that the Case method actually uses *more* lines of code that just using If/End If over and over....

 

Are there other benefits to using "Case" that I'm missing???

 

Thanks. -steve

 

I used SWITCH/CASE for the first time yesterday and despite its initial unfamiliarity I reckon it's easier to write & understand later, and probably on average more compact than IF/END IF.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...