Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Case Select | Excel Worksheet Functions | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
What is the difference between for..if, case statements, do..while? | Excel Programming | |||
End Select without Select Case, Block If without End If errors | Excel Programming |