ur

Switch not working

3 posts in this topic

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.

switch.PNG

Any suggestions please...

Share this post


Link to post
Share on other sites



ur,

Works fine for me:

#include <MsgBoxConstants.au3>

Local $sMsg = ""

Switch @HOUR
    Case 6 To 11
        $sMsg = "Good morning"
    Case 12 To 17
        $sMsg = "Good Afternoon"
    Case 18 To 21
        $sMsg = "Good Evening"
    Case Else
        $sMsg = "Go to bed!"
EndSwitch

MsgBox($MB_SYSTEMMODAL, @HOUR, $sMsg)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@ur

If you want help with a picture, go to an image related forum, if you want help with a script, post the script and not a screenshot of it.

If this script were bigger, and you wanted help with it, someone who wanted to run your script would have to retype the whole thing because all we have is a screenshot. People tend to ignore you when you post screenshots of a text file, post the text next time.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


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

  • Similar Content

    • WoodGrain
      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!
    • SaeidN
      By SaeidN
      Hi,
      I want to tell pixelsearch to search for red color shades in for example 5 different x,y,h,w of the screen. If color red was not found in these 5 area, then do something.
      I wrote this, but it's working only if the first case is not found. Is select a good choice? or it's better to use switch or if or something else?
      ٍEdit: all "do something"s are same function. (search for red color untill in these 5 areas, it couldnot find red color, then if it couldn't find red color, perform that 1 function)
      Thanks
      Select Case 1 $color1 = PixelSearch(67, 614, 77, 617, 0xE62121, 10) If @error Then do something... EndIf Case 2 $color2 = PixelSearch(165, 614, 175, 617, 0xE62121, 10) If @error Then do something... EndIf Case 3 $color3 = PixelSearch(265, 614, 275, 617, 0xE62121, 10) If @error Then do something... EndIf Case 4 $color4 = PixelSearch(365, 614, 375, 617, 0xE62121, 10) If @error Then do something... EndIf Case 5 $color5 = PixelSearch(465, 614, 475, 617, 0xE62121, 10) If @error Then do something... EndIf EndSelect  
    • lgvlgv
      By lgvlgv
      Hi all!
      I have a problem with creating the right varibles in the switch statment and wonder if some on can help me figure out the best way to procide?
      i got the part when i create all trayitems with a "FOR" statement from an ini file working, but i fail when it comes to the switch statement.
      ini file look like this..
      [Links]
      Calulator=Calc.exe
      and so on...
       
      here is part of my script..
      it works for a few min.. then the hole application hangs (when compiled, seems to work in test mode, before i compile it?)
      is this part that seems to cose the error?
      Case Else If $Msg > 0 Then _DebugOut("While Statement - $Msg: " & $Msg) $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0) If @error Then Else $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0) If @error Then Else _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0]) _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1]) ShellExecute($Linksarray[$aSearch][1], "", "", "open") EndIf EndIf EndIf here is both functions...
      Func _WinMain() _readConfigFile() Opt("TrayMenuMode", 11) Opt("GUIOnEventMode", 0) ;0=disabled, 1=OnEvent mode enabled _TrayInit() ; Main GUI Loop Local $tvHandle = 0 $iBegin = TimerInit() $LatencyUrl = IniRead($ConfigFile, "General", "LatencyUrl", "www.charger.se") $LatencyMS = IniRead($ConfigFile, "General", "LatencyMS", "500") HotKeySet("+!z", '_ShowITSupport') HotKeySet("+!x", '_ShowITSupport') While 1 $Msg = GUIGetMsg() $gText = _GetMenuText($Msg) If TimerDiff($iBegin) > 5000 Then ; Loop until 5 sec have passed _Ping($LatencyUrl, $LatencyMS) #cs Local $net_test = _IsInternetConnectedEx() ; ConsoleWrite("$net_test: " & $net_test & @CRLF) If $net_test = 1 Then Local $net_test2 = __GetConnectedAdapterIPMAC() If StringInStr($net_test2, "Wireless") Or StringInStr($net_test2, "Wired") Then EndIf Else ConsoleWrite("$net_test2? " & __GetConnectedAdapterIPMAC() & @CRLF) EndIf #ce ; ConsoleWrite("Counter: " & $iBegin & @CRLF) $iBegin = TimerInit() EndIf Switch $Msg Case $ToggleLogonUser _DebugOut("While Statement - $ToggleLogonUser: " & $gText) _ToggleLogonUser() Case $TrayTS _DebugOut("While Statement - $TrayTS: " & $gText) _DebugOut(@ScriptDir & "TeamViewerQS_sv-idcnnz7xxq.exe" & @CRLF) FileInstall("Res\TeamViewerQS_sv-idcnnz7xxq.exe", @ScriptDir & "\TeamViewerQS_sv-idcnnz7xxq.exe", 0) ShellExecute("TeamViewerQS_sv-idcnnz7xxq.exe", "", @ScriptDir, 'open') ; Sleep(10000) Case $ResetInternet _DebugOut("While Statement - $ResetInternet: " & $gText) $tmpNessage = MsgBox(20, "Warning", "You are about to do a complete Network reset!") If $tmpNessage = 6 Then _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage) Else _DebugOut("While Statement - $ResetInternet: MsgBox, Returns: " & $tmpNessage) EndIf Case $TrayExit _DebugOut("While Statement - $TrayExit: " & $gText) _TrayIconDelete($nTrayIcon1) ExitLoop Case Else #cs If $Msg > 0 Then _DebugOut("While Statement - $Msg: " & $Msg) $aSearch = _ArraySearch($Linksarray, $gText, 0, 0, 0, 1, 1, 0) If @error Then Else $aSearch1 = _ArraySearch($Linksarray, $Linksarray[$aSearch][0], 0, 0, 0, 1, 1, 0) If @error Then Else _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][0]) _DebugOut("While Statement - $aSearch1: " & $Linksarray[$aSearch1][1]) ShellExecute($Linksarray[$aSearch][1], "", "", "open") EndIf EndIf EndIf #ce EndSwitch Sleep(10) WEnd _TrayIconDelete($nTrayIcon1) EndFunc ;==>_WinMain Func _TrayInit() Opt('TrayMenuMode', 3) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt('TrayAutoPause', 0) ; Script will not be paused when clicking the tray icon. ;Opt("TrayOnEventMode", 1) Opt('MustDeclareVars', 0) ; *** Create the tray icon *** ;Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0) ;TraySetIcon(@ScriptFullPath, "201") $nTrayIcon1 = _TrayIconCreate("Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2, @ScriptFullPath, -1) _TrayIconSetClick(-1, 16) _TrayIconSetState() ; Show the tray icon ; *** Create the tray context menu *** Local $iIndex = _ArraySearch($GeneralArray, "Kund", 0, 0, 0, 1, 1, 0) $TrayMenuname = "ChaQ - " & $GeneralArray[$iIndex][1] $nTrayMenu1 = _TrayCreateContextMenu() ; is the same like _TrayCreateContextMenu(-1) or _TrayCreateContextMenu($nTrayIcon1) $nSideItem3 = _CreateSideMenu($nTrayMenu1) _SetSideMenuText($nSideItem3, $TrayMenuname) _SetSideMenuColor($nSideItem3, 0x00FFFF) ; yellow; default color - white _SetSideMenuBkColor($nSideItem3, 0x802222) ; bottom start color - dark blue _SetSideMenuBkGradColor($nSideItem3, 0x4477AA) ; top end color - orange _SetSideMenuImage($nSideItem3, "shell32.dll", 309, True) $TrayCase = _TrayCreateItem("SupportCenter, Add a Case") _TrayCreateItem("") _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7) $TrayTS = _TrayCreateItem("Teamviwer") _TrayCreateItem("") _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9) $MenuLinks = _TrayCreateMenu("Links") _TrayCreateItem("") _TrayItemSetIcon($MenuLinks, "shell32.dll", -44) $MenuTools = _TrayCreateMenu("Program") _TrayCreateItem("") _TrayItemSetIcon($MenuTools, "", 0) $chargeitem = _TrayCreateMenu("Tools") $chargeitem1 = _TrayCreateMenu("Settings", $chargeitem) _TrayCreateItem("") $TrayExit = _TrayCreateItem("Exit") _TrayItemSetIcon($TrayCase, @ScriptFullPath, -7) _TrayItemSetIcon($MenuLinks, "shell32.dll", -318) _TrayItemSetSelIcon($MenuLinks, "shell32.dll", -44) _TrayItemSetIcon($MenuTools, "shell32.dll", -20) _TrayItemSetSelIcon($MenuTools, "shell32.dll", -20) _TrayItemSetIcon($chargeitem, @ScriptFullPath, -11) _TrayItemSetSelIcon($chargeitem, @ScriptFullPath, -11) _TrayItemSetIcon($chargeitem1, @ScriptFullPath, -11) _TrayItemSetSelIcon($chargeitem1, @ScriptFullPath, -11) _TrayItemSetIcon($TrayHelp, "mstsc_101.ico", 0) _TrayItemSetIcon($TrayTS, @ScriptFullPath, -9) _TrayItemSetIcon($TrayExit, "shell32.dll", -28) ; *** Sub menu items *** For $x = 1 To $Linksarray[0][0] _DebugOut("$Linksarray " & $Linksarray[$x][0]) If StringInStr($Linksarray[$x][1], "http") Then $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuLinks) _TrayItemSetIcon($Tray_Item[$x], "shell32.dll", -14) Else $Tray_Item[$x] = _TrayCreateItem($Linksarray[$x][0], $MenuTools) _TrayItemSetIcon($Tray_Item[$x], $Linksarray[$x][1], "") EndIf Next $EnableBit = _TrayCreateItem("Enable (BIT/WSUS)", $chargeitem) $DisableBit = _TrayCreateItem("Disable (BIT/WSUS)", $chargeitem) $ResetInternet = _TrayCreateItem("Reset Internet Connection", $chargeitem) $ToggleLogonUser = _TrayCreateItem("Toggle Username/logon screen", $chargeitem) _TrayItemSetIcon($TrayTSSite, "shell32.dll", -14) _TrayItemSetIcon($TraySupportSite, "shell32.dll", -14) _TrayItemSetIcon($TraySupportSite1, "shell32.dll", -14) _TrayItemSetIcon($DisableBit, "shell32.dll", -275) _TrayItemSetIcon($EnableBit, "shell32.dll", -276) _TrayItemSetIcon($ResetInternet, @ScriptFullPath, -12) _TrayItemSetIcon($ToggleLogonUser, "regedit.exe", -1) GUICtrlSetState($chargeitem, $GUI_DISABLE) GUICtrlSetState($EnableBit, $GUI_DISABLE) GUICtrlSetState($DisableBit, $GUI_DISABLE) GUICtrlSetState($ResetInternet, $GUI_DISABLE) EndFunc ;==>_TrayInit  
    • Kronitron
      By Kronitron
      I taught myself how to script and have done some pretty basic stuff so far.  I wrote the script below to detect the current orientation of my monitor, then switch it to a different orientation. 
      I'm bored and I've got the day off, so I'd like to tackle a new challenge.  Please review the script below to get an idea of my skill level, then suggest something challenging for me to write.  Just no API usage.  Thanks!
      $Desktop_Height = @DesktopHeight $Desktop_Width = @DesktopWidth Run("control desk.cpl") WinWaitActive("Screen Resolution") ControlSend("Screen Resolution", "", "", "!o") If $Desktop_Height < $Desktop_Width Then ControlSend("Screen Resolution", "", "", "{Down}") ElseIf $Desktop_Height > $Desktop_Width Then ControlSend("Screen Resolution", "", "", "{Up}") EndIf ControlSend("Screen Resolution", "", "", "!a") WinWaitActive("Display Settings") ControlSend("Screen Resolution", "", "", "!k") WinWaitActive("Screen Resolution") ControlSend("Screen Resolution", "", "", "!{F4}") Exit  
    • Kovacic
      By Kovacic
      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)