Jump to content

Nested Switch question


Recommended Posts

Can you nest switches? I have nested switches sometimes 3 deep in my app, yet au3Check will pick random endswitch statements and tell me its missing a Wend..

 

example:

switch
Case $1 = "Option A"
;do something
Case $1 = "Option B"
;do something
Case $1 = "Option C"
        switch
        Case $A = "Enabled"
        ;do something
        Case $A = "Disabled"
        ;do something
        Endswitch
Case $1 = "Option H"
;do something
Endswitch

 

One of the errors I got in my script:

 

"C:\1\2.au3"(1471,4) : error: missing Wend.
                        EndSwitch
                        ^

 

My script is too large to post, (over 3k in total size)

 

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

You will sometimes get odd errors if you don't use the correct syntax. You are confusing 'Switch' statement syntax with 'Select' statement syntax. Here is the corrected syntax.

Local $1, $A ; added for syntax check

Switch $1
    Case "Option A"
        ;do something
    Case "Option B"
        ;do something
    Case "Option C"
        Switch $A
            Case "Enabled"
                ;do something
            Case "Disabled"
                ;do something
        EndSwitch
    Case "Option H"
        ;do something
EndSwitch

 

Edited by czardas
Link to comment
Share on other sites

There is no issue with nested switch statements. You just need to use the correct syntax.

You need to tell the switch command "what" you are wanting to switch.

switch $A                                              ; I want to check variable $A
    case "apple"                                       ; does variable $A = "apple"?
        msgbox(0,"","","It's an apple")                ; tell me it's an apple
    case "banana"                                      ; does variable $A = "banana"
        msgbox(0,"","","It's a banana")                ; tell me it's a banana
    case "car"                                         ; does variable $A = "car"
        switch $B                                      ; I want to check variable $B
            case "audi"                                ; does variable $B = "audi"
                msgbox(0,"","","Your car is an audi")  ; tell me it's a car and an audi
            case "bmw"                                 ; does variable $B = "bmw"
                msgbox(0,"","","Your car is a bmw")    ; tell me it's a car and a bmw
        endswitch                                      ; finish testing variable $B
endswitch                                              ; finish testing variable $A

 

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...