Jump to content

Problem with SELECT


Recommended Posts

Hello

I have hesitate to use while, elseif or switch or select

I have make this script.

Local $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

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 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

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 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

  • Moderators
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

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

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

  • Moderators
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.

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...