Embedded or nested Select Case statements 
Author Message
 Embedded or nested Select Case statements

Is it possible to embed or nest Select Case statements?  I would like to
brach from one Select Case into another.  I start with three choices -
A, B, C.  Each of those could go in three different directions {1, 2,
3}, {4, 5, 6} and {7, 8, 9}.  I thought a simple select case with each
branch leading into another select case statement would work very nicely
but I get compile errors saying that "Statements and labels invalid
between Select Case and first Case."   Any thoughts would be
appreciated.
John D. Baumgartner



Sun, 15 Oct 2000 03:00:00 GMT  
 Embedded or nested Select Case statements

Hi John,

    Should be doable.  Please include your code if your question is code
specifc.  It helps us (well me at least) understand what's causing the
errors.

    Select Case strIN    'can be A B C
        Case "A":
            Select Case WeekDay(Date):    'just as an example
                Case 1:
                    MsgBox "1 for A"
                Case 2:
                    MsgBox "2 for A"
                Case 3:
                    MsgBox "3 for A"
                Case Else: MsgBox "Weekday different for A"
            End Select
        Case "B":
            Select Case WeekDay(Date):    'just as an example
                Case 1:
                    MsgBox "1 for B"
                Case 2:
                    MsgBox "2 for B"
                Case 3:
                    MsgBox "3 for B"
                Case Else: MsgBox "Weekday different B"
            End Select
        Case "C":
            Select Case WeekDay(Date):    'just as an example
                Case 1:
                    MsgBox "1 for C"
                Case 2:
                    MsgBox "2 for C"
                Case 3:
                    MsgBox "3 for C"
                Case Else: MsgBox "Weekday different C"
            End Select
        Case Else:  'do nothing
    End Select

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Quote:

>Is it possible to embed or nest Select Case statements?  I would like to
>brach from one Select Case into another.  I start with three choices -
>A, B, C.  Each of those could go in three different directions {1, 2,
>3}, {4, 5, 6} and {7, 8, 9}.  I thought a simple select case with each
>branch leading into another select case statement would work very nicely
>but I get compile errors saying that "Statements and labels invalid
>between Select Case and first Case."   Any thoughts would be
>appreciated.
>John D. Baumgartner



Sun, 15 Oct 2000 03:00:00 GMT  
 Embedded or nested Select Case statements

Try using a sub or function (as needed) for the lower level case handler.
Call it with the appropriate information from the upper level case handler.
What you're trying to do right now violates structured coding conventions.

Mike Ober.

Quote:

>Is it possible to embed or nest Select Case statements?  I would like to
>brach from one Select Case into another.  I start with three choices -
>A, B, C.  Each of those could go in three different directions {1, 2,
>3}, {4, 5, 6} and {7, 8, 9}.  I thought a simple select case with each
>branch leading into another select case statement would work very nicely
>but I get compile errors saying that "Statements and labels invalid
>between Select Case and first Case."   Any thoughts would be
>appreciated.
>John D. Baumgartner



Sun, 15 Oct 2000 03:00:00 GMT  
 Embedded or nested Select Case statements


says...

Quote:
> I thought a simple select case with each
> branch leading into another select case statement would work very nicely
> but I get compile errors saying that "Statements and labels invalid
> between Select Case and first Case."

THat's true, nothing can go there. But it sounds like code like this
should work for you:

Select Case Value1
  Case "A"
    Select CAse Value2
      Case 1
      Case 2
      CAse 3
    End Select
  Case "B"
    Select Case Value2
      Case 4
      Case 5
      Case 6
    End Select
  Case "C"
    Select Case Value2
      Case 7
      Case 8
      Case 9
    End Select
End Select

-- Ken



Sun, 15 Oct 2000 03:00:00 GMT  
 Embedded or nested Select Case statements

Mike,

Could you please explain this a little more:

Quote:
> What you're trying to do right now violates structured coding conventions.

If you have an action which is dependent on two variables, what is the
violation in nesting the second variable inside the first?  

Example:  I need to use a different formula for a calc depending on two
variable in the sub.  What would you recommend other than this:

Select Case Var1
        Case 1
                Select Case Var2
                Case A
                        MyFunc = Var3*Var2
                Case B
                        MyFunc = Var3/Var2
                End Select
        Case 2
                Select Case Var2
                Case A
                        MyFunc = Var3*Var2*5
                Case B
                        MyFunc = Var3
                End Select
End Select

I'm curious because I do have this situation (although not with such
silly data) and would be happy to know a better way.

Keri Hardwick



Sun, 15 Oct 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Can you nest Select Case statements?

2. VBScript Select Case vs VB Select Case

3. ExitSelect & Nested Select Statements

4. Select Case Statement Help

5. Select Case Statement

6. Criteria for select case statements

7. Using a wildcard string comparison in a select case statement

8. Select Case statement is driving me mad!

9. If...Then...Else or Select Case Statement

10. Select Case Statement

11. If statement in select case problem

12. Select Case Statement

 

 
Powered by phpBB® Forum Software