Case with more options

  • Thread starter Thread starter Marcolino
  • Start date Start date
M

Marcolino

Hi,
I have a particular need and I tryed to use this code:

Select Case i
Case 1 or 100
Istructions 1
Case 2 or 100
Istructions 2
Case 3 or 100
Istructions 3
End Select

In deep I need that:
if i=1 or 2 or 3 i need to execute the single instruction contained in
a single case.
If i=100 i need to execute all instruction.
This code does not work, any suggestions?

Thanks
 
Case 1,100

For such things, I would also strongly recommend to hit the F1 key and check
the documentation before posting...
 
How about this:
Select Case i
Case 1
Istructions 1
Case 2
Istructions 2
Case 3
Istructions 3
Case 100
Istructions 1
Istructions 2
Istructions 3
End Select
?

vovan
 
I forgot though that this select the *first* case that match the value i.e.
with 100, it will select just the first case statement.

So it becomes more an approach than just a syntax issue...

The general case is that this is *not* a choose between several so I would
just :

- use a series of if statements if you don't have something callable (i.e. a
routine or function) for each case :
If i=1 or i=100 then
' Statements...
End If
If i=2 Or i=100 Then
' Statements
End If
etc...

If each case calls a function or routine I would separate the 100 case :

Select Case i
Case 1
DoWork1
Case 2
DoWork2
Case 3
DoWork3
Case 100
DoWork1
DoWork2
DoWork3
End Select
 
Case 1,100

For such things, I would also strongly recommend to hit the F1 key and check
the documentation before posting...

--
Patrice

"Marcolino" <[email protected]> a écrit dans le message de (e-mail address removed)...







- Mostra testo tra virgolette -

Hi,
Thanks for your answer, I checked the Help with F1 Keys before
posting,
but this code does not work:

Select Case i
Case 1,100
Istructions 1
Case 2,100
Istructions 2
Case 3,100
Istructions 3
End Select

This code will execute only Instruction 1 if i=100. This is not my
need.

Bye
 
I forgot though that this select the *first* case that match the value i.e..
with 100, it will select just the first case statement.

So it becomes more an approach than just a syntax issue...

The general case is that this is *not* a choose between several so I would
just :

- use a series of if statements if you don't have something callable (i.e.a
routine or function) for each case :
If i=1 or i=100 then
    ' Statements...
End If
If i=2 Or i=100 Then
    ' Statements
End If
etc...

If each case calls a function or routine I would separate the 100 case :

Select Case i
    Case 1
        DoWork1
    Case 2
        DoWork2
    Case 3
        DoWork3
    Case 100
        DoWork1
        DoWork2
        DoWork3
End Select

--
Patrice

"Patrice" <http://www.chez.com/scribe/> a écrit dans le message de (e-mail address removed)...





- Mostra testo tra virgolette -

Thanks Patrice,
but reply is arriving slowly.
I think that will use IF Then options, because DoWorkXX is a lot of
instruction and I would not to replicate it under "Case 100" options.

Many Thanks for your suggestion.

--Marco
 
Hi,

it would be more like this:

Rather than using Select Case, I would use 3 If...Then statements.

If i = 1 OrElse i = 100 Then
Instructions 1
End If

If i = 2 OrElse i = 100 Then
Instructions 2
End If

If i = 3 OrElse i = 100 Then
Instructions 3
End If
 
Marcolino said:
Select Case i
Case 1 or 100
Istructions 1
Case 2 or 100
Istructions 2
Case 3 or 100
Istructions 3
End Select

In deep I need that:
if i=1 or 2 or 3 i need to execute the single instruction contained in
a single case.
If i=100 i need to execute all instruction.
This code does not work, any suggestions?

\\\
Select Case i
Case 1, 2, 3
Instructions
Case 100
Instructions
End Select
///
 
Yes, sorry about that. I realized that afterwards. I first thought at first
sight it was just a syntax issue...

--
Patrice

"Marcolino" <[email protected]> a écrit dans le message de (e-mail address removed)...
Case 1,100

For such things, I would also strongly recommend to hit the F1 key and
check
the documentation before posting...

--
Patrice

"Marcolino" <[email protected]> a écrit dans le message de (e-mail address removed)...







- Mostra testo tra virgolette -

Hi,
Thanks for your answer, I checked the Help with F1 Keys before
posting,
but this code does not work:

Select Case i
Case 1,100
Istructions 1
Case 2,100
Istructions 2
Case 3,100
Istructions 3
End Select

This code will execute only Instruction 1 if i=100. This is not my
need.

Bye
 
Herfried,

I had expected more from you

:-)

I would go for the three if's or easier the case where the one for 100 was
including a method to do instructions 1, 2 and 3

Cor
 
The documentation on Select Case specifies that one and only one of the
selections will run. After any one of the selections satisfies the
condition, the code within it will run and then Select Case will finish
up.

You will need to so something completely different with If statements to
do this. I don't have time to write something up but it should be
obvious after you realize that Select Case cannot do this type of
operation and look elsewhere.

Or, maybe, if the numbers were just right, you could add or Or them
together before coming into the Select but this would certainly be
"funny code" that might break tomorrow after some other option is added.

Mike
 
The documentation on Select Case specifies that one and only one of the
selections will run. After any one of the selections satisfies the
condition, the code within it will run and then Select Case will finish
up.

You will need to so something completely different with If statements to
do this. I don't have time to write something up but it should be
obvious after you realize that Select Case cannot do this type of
operation and look elsewhere.

Or, maybe, if the numbers were just right, you could add or Or them
together before coming into the Select but this would certainly be
"funny code" that might break tomorrow after some other option is added.

Mike

Perhaps

if i = 100 then
Instructions1()
Instructions2()
Instructions3()
else
select case i
case 1
Instructions1()
case 2
Instructions2()
case 3
Instructions3()
end select
endif

or maybe

select case i
case 1
Instructions1()
case 2
Instructions2()
case 3
Instructions3()
case 100
Instructions1()
Instructions2()
Instructions3()
end select

LS
 
Back
Top