Jump to content

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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By abberration
      Software Installer
      Version: 2.0
      It's been been a long year, but I finally got some time to rework this project. I re-wrote everything from scratch because the old version was getting too complicated with so many options and sub-menus. This new version is much easier to use and I have been testing for a few days and it seems very stable.
      For those who are new to this software, it helps you install software silently/unattended. This new version tries to determine the silent switch automatically. You can also re-organize the order in which the software installs by dragging & dropping them in the listview. It now supports creating profiles and checks for missing software (and automatically unchecks them, so it does not attempt to install non-existent software). One feature I included was because I have seen several people on Youtube talk about disliking bright screens at night. So, now you can choose from a few color theme (half of them are dark). I dabbled a bit more into GDI+ to draw a few things and show my logo with a transparent background (hint: I'm not good at GDI+).
      Under the Help menu, you will find a User Guide, which goes through most of it's features. I included a new icon if you want to use when you compile the script (in the Assets > Misc folder).
      If you have questions, comments or suggestions, all are welcome. Hope you enjoy!
      Here it is in action:

       
      Software_Installer_2.0.zip
    • By Jemboy
      Recently I was working on a script with icons using GuiCtrkCreatIcon.
      I decided to change the sub folder name of the icons to a more meaning name, however made a typo.

      I tested the .exe on my test computer and it worked flawlessly (because both icon folder where on my test computer) 😁
      But after I installed the script on the intended computers , I got chaos!😵
      Zooming into the problem, I discovered, that because the icons could not be found, the ControlID were returned with a value of 0
      and thus played havoc within the GuiGetMsg() switch/case statement.
      I have been able to reproduce this  (see example)
      #include <GUIConstantsEx.au3> ;============================================================================================================ ; PLEASE, do not save this example in the example folder: C:\Program Files (x86)\AutoIt3\Examples\Helpfile ;============================================================================================================ Example() Func Example() GUICreate(" My GUI Icons", 250, 250) $Icon1 = GUICtrlCreateIcon("shell32.dll", 10, 20, 20) $Icon2 = GUICtrlCreateIcon(@ScriptDir & '\Extras\horse.ani', -1, 20, 40, 32, 32) $Icon3 = GUICtrlCreateIcon("shell32.dll", 7, 20, 75, 32, 32) GUISetState(@SW_SHOW) ;$Icon2 = -1 ; ==> When this line is uncommented the script "works", so -1 could be a potential fix. ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Icon2 Beep (500,500) EndSwitch WEnd GUIDelete() EndFunc ;==>Example If you save the above script outside the Autoit example folder and run it, it will keep beeping because GuiCtrlCreatIcon did not find horse.ani and return $Icon2=0.
      At the moment GUICtrlCreateIcon () only returns the conntrolID on success and 0 on failure.
      I would like to propose a return of -1 on failure, so a existing and working script won't go awry when the icon can not be found.
       
    • By Skysnake
      From From here, bottom of the post
      I am not arguing the logic of this, merely would like to point out that if there is such a rule, it is not documented...  Are there other such rules?
      Skysnake
    • By WoodGrain
      Hi guys,
      Could someone please tell me what I'm doing wrong with this code?
      I'm trying to take user input and then run a function with the same name, but it's not calling the function.
      So in the below after pressing Shift+F8 I would enter the text (without quotes) "testFunc".
      As you can see I've also tried this with IF statements, I'm new to using Switch/Case.
      HotKeySet("+{F8}", RunManually) Func RunManually() ;Use a case statement with 1 hot key and an InputBox to manually run functions $funcName = InputBox("Which Func to Run?", "Enter the name of the function to run") MsgBox(0, "Entered value", $funcName) ;If $funcName = testFunc Then testFunc() ;If $funcName = test2Func Then test2Func() Switch $funcName Case testFunc MsgBox(0, "Calling", "Calling Function") testFunc() MsgBox(0, "Called", "Function call finished") Case test2Func MsgBox(0, "Calling", "Calling Function") test2Func() MsgBox(0, "Called", "Function call finished") EndSwitch EndFunc While 1 ;testFunc() Sleep(1000) WEnd Func testFunc() MsgBox(0, "func running", "Seems to work!") EndFunc Func test2Func() MsgBox(0, "func 2 running", "2 Seems to work!") EndFunc Thanks!
    • By ur
      I have never used switch in AutoIT earlier.
       
      But today, when I started to implement it in my code, I am getting errors.
      So I tried to execute default example, but still getting the same error.

      Any suggestions please...
×
×
  • Create New...