AutoDEV Posted April 3 Share Posted April 3 Hello I have hesitate to use while, elseif or switch or select I have make this script. expandcollapse popupLocal $pic1 = "test1.png" Local $pic2 = "test2.png" Local $pic3 = "test3.png" Local $pic4 = "test4.png" Func _searchIMG() Select Case 'pic1.png' $pic1 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic1.png" 1, 100) If IsArray($pic1) Then MsgBox(0, '', 'img 1 found') EndIf Case 'pic2.png' $pic2 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic2.png", 1, 100) If IsArray($pic2) Then MsgBox(0, '', 'img 2 found') EndIf Case 'pic3.png' $pic3 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic3.png", 1, 100) If IsArray($pic3) Then MsgBox(0, '', 'img 3 found') EndIf Case 'pic4.png' $pic4 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic4.png", 1, 100) If IsArray($pic4) Then MsgBox(0, '', 'img 4 found') EndIf EndSelect Return $searchShip EndFunc When i have found one pictures i want exit select. Can you help me please ? TY Link to comment Share on other sites More sharing options...
argumentum Posted April 3 Share Posted April 3 ...If you only read the help file ( https://www.autoitscript.com/autoit3/docs/keywords/Select.htm ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 3 Share Posted April 3 (edited) Hi @AutoDEV , besides the smart hint of @argumentum which should answer your statement/question "When i have found one pictures i want exit select.", your code is not working (again 😒). Please try to provide working scripts and provide more information about what do you want to achieve. 7 hours ago, AutoDEV said: I have hesitate to use while, elseif or switch or select Why do you hesitate? The help provides often really good examples of how to use this or that etc. Please try to use the help first and ask us in case you really cannot proceed. If you want to get suggestions about questions regarding "when should I use a Select-Block or a Switch-Block"; "when should I use if-else instead" ... etc., then please help us by more context. Best regards Sven Edited April 3 by SOLVE-SMART Stay innovative! 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) Link to comment Share on other sites More sharing options...
AutoDEV Posted April 3 Author Share Posted April 3 Hello. My problem is : I need exit select if i have found one imqge. Like Break in php. TY Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted April 3 Share Posted April 3 (edited) I cannot help you if you're not willing to use the answers and hints that people give you here. See the help file - it is describing about the execution in the Select-Block. Also Case 'pic1.png' isn't a valid expression. Valid would be (for example) something like this: Local Const $sImage = 'pic1.png' Select Case $sImage = 'pic2.png' ; this is false and will not be executed Case $sImage = 'pic1.png' ; do something, because this Case is true ; the Select-Block will be leaved Case $sImage = 'pic3.png' ; will never be checked, because the second Case was true ; ... ; ... ; ... EndSelect Better would be the usage of a Switch-Block... also see the help. Best regards Sven Edited April 3 by SOLVE-SMART Stay innovative! 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) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 3 Moderators Share Posted April 3 12 hours ago, AutoDEV said: Select Case 'pic1.png' The case statement will continue if the statement is true. 'pic1.png' does not have a false/0 value. It's meant to have a conditional value such as "If $sValue = 'pic1.png' Then", in this case it would be more like "Case sValue = 'pic1.png'", since all your case statements have a relative "True" value, each case will be processed. So, you're using the "Select Case" statements incorrectly. With the way you have your case statement, if you "break" out when it is found, you'll break out every time it reaches "pic1.png" and never reach the other case statements. If you don't care, and this logic makes sense to you for some unknown reason, you can use Return <value> if you're in a function with no loop, or if you're in a loop you can use Continueloop, if you want to keep checking each case statement even if you found the one of the other statements to be true, you do as argumentative has stated and use ContinueCase. If I'm being honest, I don't think I've used a Select statement in AutoIt in 15+ years. To me it's just an If/Then statement with no other benefit. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
AutoDEV Posted April 8 Author Share Posted April 8 On 4/3/2024 at 1:52 PM, SOLVE-SMART said: I cannot help you if you're not willing to use the answers and hints that people give you here. See the help file - it is describing about the execution in the Select-Block. Also Case 'pic1.png' isn't a valid expression. Valid would be (for example) something like this: Local Const $sImage = 'pic1.png' Select Case $sImage = 'pic2.png' ; this is false and will not be executed Case $sImage = 'pic1.png' ; do something, because this Case is true ; the Select-Block will be leaved Case $sImage = 'pic3.png' ; will never be checked, because the second Case was true ; ... ; ... ; ... EndSelect Better would be the usage of a Switch-Block... also see the help. Best regards Sven Hello. I not understand. $sImage can have one value. My exemple i have 4 different pictures. How to make plz. Link to comment Share on other sites More sharing options...
Werty Posted April 8 Share Posted April 8 Quote Return $searchShip Umm, could you post one of the pics, sounds alot like a game. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
AutoDEV Posted April 10 Author Share Posted April 10 hello Where is break in switch ? My problem is, he searchj all case and i need stop to search when i have found 1 image I have never use Continueloopa ContinueCase. I have edit code. Local $pic1 = "test1.png" $pics= searchIMG("pic1.png") Func _searchIMG($img) Select Case 'pic1.png' $pic1 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic1.png" 1, 100) If IsArray($pic1) Then MsgBox(0, '', 'img 1 found') EndIf Case 'pic2.png' $pic2 = _ImageSearch(@ScriptDir & "/IMG/BUTTON/pic2.png", 1, 100) If IsArray($pic2) Then MsgBox(0, '', 'img 2 found') EndIf EndSelect EndFunc Link to comment Share on other sites More sharing options...
Musashi Posted April 10 Share Posted April 10 A simple question : do you really want to learn, or is your avatar just a abbreviation for "other people have to solve my poorly defined questions" ? SmOke_N 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 10 Moderators Share Posted April 10 6 minutes ago, Musashi said: A simple question : do you really want to learn, or is your avatar just a abbreviation for "other people have to solve my poorly defined questions" ? That makes me giggle... Whatever the case, I know other mods are already fed up with his ignorantly posturized requests. No matter what people suggest, if they don't write the code for them specifically, this OP is never satisfied to do the work or research. I know others are (including mods) are already at their limit. To the OP, start posting really worked on problems, start researching the suggestions given to you with examples on how those suggestions are not working for you, starting reading some manuals, manuals not only on coding, but maybe how to request help. I'm locking this topic, I know his last topic was locked as well. Hopefully the OP gets the hint. Andreik, SOLVE-SMART and Musashi 2 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts