Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Select Case or If - What's the difference

Hi,

I have a set of about 40 possible Boolean events that I want to examine and
carry out actions dependant on which are true (more than one may be true but
I have no way of predicting which ones; it is also possible that none of them
are true).
I think I can probably do this using either a set of If ...Then statements:

If statement1=TRUE then
Action 1
End If
If statement 2=TRUE then
Action 2
End If
or I could use a a set of Select Case statements:

Select Case TRUE
Case statement 1
Action 1
Case statement 2
Action 2
End Select

What would be considered the better solution (and why?) or is there a more
efficient way of doing this?

TIA

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Select Case or If - What's the difference

http://support.microsoft.com/kb/213630

If...Then...Else statement executes a group of statements based on the value
of an expression, and the Select Case statement executes one of several
statements based on the value of an expression


If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Hi,

I have a set of about 40 possible Boolean events that I want to examine and
carry out actions dependant on which are true (more than one may be true but
I have no way of predicting which ones; it is also possible that none of them
are true).
I think I can probably do this using either a set of If ...Then statements:

If statement1=TRUE then
Action 1
End If
If statement 2=TRUE then
Action 2
End If
or I could use a a set of Select Case statements:

Select Case TRUE
Case statement 1
Action 1
Case statement 2
Action 2
End Select

What would be considered the better solution (and why?) or is there a more
efficient way of doing this?

TIA

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Select Case or If - What's the difference

Thinking of a better solution would be to keep your boolean events as an
Array so that you can loop through the array which saves lines of code..

If this post helps click Yes
---------------
Jacob Skaria


"Risky Dave" wrote:

Hi,

I have a set of about 40 possible Boolean events that I want to examine and
carry out actions dependant on which are true (more than one may be true but
I have no way of predicting which ones; it is also possible that none of them
are true).
I think I can probably do this using either a set of If ...Then statements:

If statement1=TRUE then
Action 1
End If
If statement 2=TRUE then
Action 2
End If
or I could use a a set of Select Case statements:

Select Case TRUE
Case statement 1
Action 1
Case statement 2
Action 2
End Select

What would be considered the better solution (and why?) or is there a more
efficient way of doing this?

TIA

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Select Case or If - What's the difference

The other major difference is that the first TRUE condition will execute and
the select case code will then exit even if later case conditions are true,
think of select case as nested if statements.

This example will result in the first message box being displayed, the other
two cases are true but will be ignored.
iX = 25
Select Case iX
Case Is = 25: MsgBox "=25"
Case Is 20: MsgBox "20"
Case Is < 30: MsgBox "<30"
End Select

In this example ALL three messages are displayed sequentially
iX = 25
If iX = 25 Then MsgBox "=25"
If iX 20 Then MsgBox "20"
If iX < 30 Then MsgBox "<30"

This nested if sequence replicates the case statement, which is far easier
to understand, above!
iX = 25
If iX = 25 Then
MsgBox "=25"
Else
If iX 20 Then
MsgBox "20"
Else
If iX < 30 Then
MsgBox "<30"
Endif
Endif
Endif


--

Regards,
Nigel




"Risky Dave" wrote in message
...
Hi,

I have a set of about 40 possible Boolean events that I want to examine
and
carry out actions dependant on which are true (more than one may be true
but
I have no way of predicting which ones; it is also possible that none of
them
are true).
I think I can probably do this using either a set of If ...Then
statements:

If statement1=TRUE then
Action 1
End If
If statement 2=TRUE then
Action 2
End If
or I could use a a set of Select Case statements:

Select Case TRUE
Case statement 1
Action 1
Case statement 2
Action 2
End Select

What would be considered the better solution (and why?) or is there a more
efficient way of doing this?

TIA

Dave


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case Select NoodNutt Excel Worksheet Functions 7 September 21st 08 02:10 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
What is the difference between for..if, case statements, do..while? [email protected] Excel Programming 1 September 6th 07 12:16 AM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM


All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"