Champak Posted December 2, 2024 Posted December 2, 2024 I'm trying to jump to a case if certain conditions are met in a preceding case. I tried coding it like the example below, but it doesn't work. It works up to "case $ccc, $ddd" but it doesn't then jump to "case $hhh". Is there some way to accomplish this? func something() switch $22 case $aaa, $bbb, $ccc, $ddd, $eee switch $22 case $ccc, $ddd $22 = $hhh endswitch case $fff case $ggg case $hhh ;Something else here case $iii endswitch Endfunc ย
ioa747 Posted December 2, 2024 Posted December 2, 2024 (edited) Global $aaa, $bbb, $ccc, $ddd, $eee, $fff, $ggg, $hhh, $iii, $22 $ccc = "$ccc" $hhh = "$hhh" $22 = $ccc ConsoleWrite("$22=" & $22 & @CRLF) something() ConsoleWrite("$22=" & $22 & @CRLF) func something() switch $22 case $aaa, $bbb, $ccc, $ddd, $eee ConsoleWrite(" 1 $22=" & $22 & @CRLF) switch $22 case $ccc, $ddd $22 = $hhh ConsoleWrite(" 2 $22=" & $22 & @CRLF) Return something() endswitch case $fff case $ggg case $hhh ;Something else here $22 = "Something else here" ConsoleWrite(" 3 $22=" & $22 & @CRLF) case $iii endswitch Endfunc After a second (or even third) look, this seems like a safer approach to me. Global $aaa, $bbb, $ccc, $ddd, $eee, $fff, $ggg, $hhh, $iii, $22 $ccc = "Value of ccc" $hhh = "Value of hhh" $22 = $ccc ConsoleWrite("$22=" & $22 & @CRLF) something() ConsoleWrite("$22=" & $22 & @CRLF) Func something() Local $bOneMoreTime = True While $bOneMoreTime $bOneMoreTime = False Switch $22 Case $aaa, $bbb, $ccc, $ddd, $eee ConsoleWrite(" 1 $22=" & $22 & @CRLF) Switch $22 Case $ccc, $ddd $22 = $hhh ConsoleWrite(" 2 $22=" & $22 & @CRLF) $bOneMoreTime = True EndSwitch Case $fff Case $ggg Case $hhh $22 = "Something else here" ConsoleWrite(" 3 $22=" & $22 & @CRLF) Case $iii EndSwitch WEnd EndFunc ย Edited December 2, 2024 by ioa747 UpDate I know that I know nothing
pixelsearch Posted December 2, 2024 Posted December 2, 2024 maybe this ? Func something() Switch $22 Case $aaa, $bbb, $ccc, $ddd, $eee ; lines of code here, common to $aaa, $bbb, $ccc, $ddd, $eee then... If $22 = $ccc Or $22 = $ddd Then ContinueCase Case $hhh ; moved here to allow the previous ContinueCase ; lines of code executed when $22 = $ccc or $ddd or $hhh Case $fff Case $ggg Case $iii EndSwitch EndFunc ย "I think you are searching a bug where there is no bug... don't listen to bad advice."
MattyD Posted December 3, 2024 Posted December 3, 2024 Also another option... Switch $Var Case $Case1, $Case2, $Case3, $Case4 ;Do Something here If ($Var = $Case3) Or ($Var = $Case4) Then DoSomethingElse($Var) Case $Case5 Case $Case6 DoSomethingElse($Var) EndSwitch Func DoSomethingElse($Var) ConsoleWrite(StringFormat("$Var = %s", $Var)) EndFunc
SOLVE-SMART Posted December 8, 2024 Posted December 8, 2024 Hi @Champakย ๐ , the answers are all fine. My 2 Cents for such things: Try to avoid such nested case handling at all. Maybe the usage of polymorphism can help you. And yes, I know, AutoIt is not OOP based, but the approach of polymorphism is adaptable ๐ . Best regards Sven ==> AutoIt related: ๐ GitHub, ๐ Discord Server, ๐ Cheat Sheet Spoiler ๐ย Au3Forums ๐ฒ AutoIt (en) Cheat Sheet ๐ AutoIt limits/defaults ๐ Code Katas: [...] (comming soon) ๐ญ Collection of GitHub users with AutoIt projects ๐ย False-Positives ๐ฎย Me on GitHub ๐ฌย Opinion about new forum sub category ๐ย UDF wiki list โย VSCode-AutoItSnippets ๐ย WebDriver FAQs ๐จโ๐ซย WebDriver Tutorial (coming soon)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now