Jump to content
Sign in to follow this  
Schoening

Multiple Select Case Problem {SOLVED}

Recommended Posts

Schoening

While i am waiting for Better Solutions for Finding Multiple @error Cases and React according to them, i am hoping that some1 could explain me what my problem in this (time consuming) function is..

The Idea is that i check for @Errors from the 3 PixelSearch i am doing, and give Message according to it.

I am changing Colors In Paint for Every Loop To Test If the Color Searches Are Correct.

All Cases are Working Fine, and the Right MsgBoxes are Triggered, Except the Case where all 3 Colors are Missing:

HotKeySet("{ESC}", "End")
Global $pixelSearchError1 = @error
Global $pixelSearchError2 = @error
Global $pixelSearchError3 = @error
While 1
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10) ;Blue
$pixelSearchError1 = @error
$pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10) ;Red
$pixelSearchError2 = @error
$pixelsearch3 = PixelSearch(500,300,600,512,0x00ff00,10) ;Green
$pixelSearchError3 = @error
Call("_errorcheck")
WEnd
Func _errorcheck()
    Sleep(100)
Select                                                        ;Check for Blue Color, Then Proceed.
        Case Not $pixelSearchError1                              ;Found Blue
            MsgBox(0,"Message","Blue Pixel Found!")
   Select                                                 ;Blue Found.  Now check for Red
    Case Not $pixelSearchError2                           ;Found Blue and Red
     MsgBox(0,"Message","Blue and Red Pixel Found!")
     Select                                       ;Blue and Red found. Now check for Green
      Case Not $pixelSearchError3                     ;Found Blue, Red and Green
        MsgBox(0,"Message","Blue,Red and Green Pixel Found!")
      Case $pixelSearchError3                             ;Blue, Red  But not Green
        MsgBox(0,"Message","Found Blue, Red But Not Green")
      EndSelect
    Case $pixelSearchError2          ;Blue Found, But Not Red
      MsgBox(0,"Message","Blue Found, But Not Red")
         Select                                       ;Blue and Red found. Now check for Green
          Case Not $pixelSearchError3                     ;Found Blue, Green But not Red
        MsgBox(0,"Message","Found Blue, Green But Not Red")
       Case $pixelSearchError3                          ;Blue, But not Red or Green
        MsgBox(0,"Message","Could only Find Blue")
      EndSelect
    EndSelect
  Case $pixelSearchError1                                    ;Blue Not Found
         MsgBox(0,"Message","Blue Pixel Not Found")
            Select                                                ;Blue Not Found.  Now check for Red
    Case Not $pixelSearchError2                           ;Found Red, But not Blue
     MsgBox(0,"Message","Found Red, But not Blue")
     Select                                       ;Found Red, But not Blue Now check for Green
      Case Not $pixelSearchError3                     ;Red and Green, but not Blue
        MsgBox(0,"Message","Red,Green But not Blue")
      Case $pixelSearchError3                             ;Red, But not  Blue or Green
        MsgBox(0,"Message","Could only Find Red")
      EndSelect
    Case $pixelSearchError2          ;Could not find Blue or Red
      MsgBox(0,"Message","Could not Find Blue and Red")
     Select                                       ;Blue and Red Not found. Now check for Green
      Case Not $pixelsearch3                      ;Only found Green
        MsgBox(0,"Message","Only found Green")
      Case $pixelSearchError3                           ;Did not Find Blue,Red or Green
        MsgBox(0,"Message","No Color was found")
     EndSelect
            EndSelect
    EndSelect
    Sleep(10)
EndFunc

I Made a Picture that should make it far easier to see where one Select Case Starts and Ends :D Check the Link Below.

http://imageshack.us/f/9/selectcasegreenerror.gif/

I can't see why the Last Case is not working.. When Blue,Red AND Green are Missing i still get the "Only found Green"

Please Help :)

Also, Building the Cases Like this takes up allot of Time and Space, so if you have a Easier way please Tell :)

Like:

If Not @error 1 And @error 2  And @error 3 Then

But i don't think that Works.

I probably want to run 5 PixelSearches and that would mean 5 Select an 32 Cases !!!1!!11

So it would be Great if there was another way of doing this ;)

If not, Please do still tell what the problem of my Function is ;)

Edited by Schoening

Share this post


Link to post
Share on other sites
Schoening

Just Click the Picture from the Link :)

Makes it far easier to figure out ;)

Share this post


Link to post
Share on other sites
ripdad

I usually don't work with pixels -- but perhaps something like this with a numbering system might give you an idea.

HotKeySet('{ESC}', 'End')
;
Local $aBlue, $aGreen, $aRed, $number, $string
;
While 1
    $number = 0

    $aBlue = PixelSearch(100, 300, 200, 512, 0x0000ff, 10); Blue
    If @error = 0 Then $number += 1
    $aRed = PixelSearch(250, 310, 400, 512, 0xfa0000, 10); Red
    If @error = 0 Then $number += 2
    $aGreen = PixelSearch(500, 300, 600, 512, 0x00ff00, 10); Green
    If @error = 0 Then $number += 4

    Switch $number
        Case 1
            $string = 'Blue'
        Case 2
            $string = 'Red'
        Case 3
            $string = 'Blue and Red'
        Case 4
            $string = 'Green'
        Case 5
            $string = 'Blue and Green'
        Case 6
            $string = 'Red and Green'
        Case 7
            $string = 'Blue, Red and Green'
        Case Else
            $string = 'No Matching Color'
    EndSwitch

    MsgBox(0, '', $string, 1)

    Sleep(10)
WEnd
;
Func End()
    Exit
EndFunc
;

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
Schoening

Where?

Look when you typed your Message, and when i had my Last Edit o.O i can't see it

Edited by Schoening

Share this post


Link to post
Share on other sites
MvGulik

Ah hah, look at the word in the first tab. "Bot".

If you can proof this topic is directly related to that file ... otherwise ... you just jumped the gun.

Where?

Screenshot. "*bot.1.au3" Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Schoening

Aha.:) Not related, found the code in attempt to find Pixelsearch information. I don't think i should link to it here since it is source code of Bot.

Though.. i can't prove that either can i ;)

Share this post


Link to post
Share on other sites
Melba23

Guys,

While we are grateful that you all try to keep this forum the kind of place we all want it to be, please do not be too aggressive - particularly to newer members. If there is some doubt as to the legality of the subject (which does not seem to be the case here) just report the thread so that a Mod can take a look - that is why we are here. :)

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
Schoening

Thx Melba ^^

Uhm... can any1 find my Error ? xD Now that i even have drawn a Helpful Picture !

Share this post


Link to post
Share on other sites
MvGulik

Nice picture indeed.

Although I'm not really getting the problem. I suggest you take a look at how to use" Not( And Or )" and maybe also take a look at ContinueCase. That should allow you to flatten than monster (eek!) of nested selects. :)

Note the Not($var1 And/or $varN+1) use. The brackets are important here.

http://www.autoitscript.com/autoit3/docs/keywords/ContinueCase.htm

http://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Schoening

Forgive me for asking this but would you mind posting a true picture of the app you are wanting to work with instead of an generic example? It may be helpful in that we may see a better way to optimize your search method.

This is all i got so far..

The only problem is that the Select Case @error Blue @error Red and @error Green Triggers Only Green ! And Not No Color Found.

I have Run all possibilities a few times.. and dont get it to work.

Share this post


Link to post
Share on other sites
Schoening

Could PixelSearch be a bit bugged?

I have now added a "Reset" after the Function:

While 1
Sleep(10)
$pixelsearch1 = PixelSearch(100,300,200,512,0x0000ff,10) ;Blue
$pixelSearchError1 = @error
$pixelsearch2 = PixelSearch(250,310,400,512,0xfa0000,10) ;Red
$pixelSearchError2 = @error
Call("_errorcheck")
$pixelSearchError1 = 0
$pixelSearchError2 = 0
$pixelSearchError3 = 0
$pixelsearch1 = 0
$pixelsearch2 = 0
$pixelsearch3 = 0
WEnd

But still the same problem

Share this post


Link to post
Share on other sites
Schoening

FIXET ! ;) I knew it was a simple Error xD

Just Used a Wrong Variable !

Typical !

Thx for all the Support, like allways ! :D and thx

MvGulik

i Look into Flattening the Code Down :)

Any Admin may {Solved} this one

Share this post


Link to post
Share on other sites
MvGulik

Good to see you found the problem.

Any Admin may {Solved} this one

You got the post count to do it yourself. Just go to your first post in this topic, switch to full edit mode for that post, and change the title to your liking. Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Schoening

Ty :)

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
Sign in to follow this  

  • Similar Content

    • tiye0405
      By tiye0405
      Hello,
      global $y, $x #RequireAdmin Global $Paused HotKeySet("{NUMPAD2}", "Pause") HotKeySet("{NUMPAD8}", "End") Opt("MouseClickDownDelay", 30) #include <ImageSearch2015.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <UpDownConstants.au3> #include <Misc.au3> Sleep(6000) Sleep(3000) $search1 = _WaitForImageSearch("goo.bmp", 30, 1, $x, $y, 10) If $search1 = 1 Then MouseMove(1500, 1500, 10) Sleep(100) MouseClick("right") Sleep(300) EndIf I've this script.
      The problem is that it work the way it is supposed to but doesnt work on a friends pc, even tho we have the same image search in C/programms(x86)/autoit3/include 
      and the same dll in system 32.
      When he starts the script on the desktop without having the "goo.bmp" file on his pc, the script finds it and right clicks the given location, while for me it doesnt and i have to open the folder with the "goo.bmp" picture in it.

      Im out of ideas on what could cause the problem.
      Any help?
      Thank you in advance
       
       
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • Xandy
      By Xandy
      I'm listing the error message strings, and roughly matching the error code
      Is this how to do error reporting?  Is there a more simple way I don't know about?
      I realise I might not need to trap @error inside $error.  I like it this way b/c I have no fear of overwriting @error now; I don't even use it.
      Func Send_Connect($address, $port)     $socket = TCPConnect($address, $port)     $error = @error     If $error <> 0 Then         Local $aError[4] = ["-2 not connected.", _                             "1 IPAddr is incorrect.", _                             "2 port is incorrect."]         $aError[3] = "10060 Connection timed out."         If $error < 0 Then $error = 0         If $error > 2 Then $error = 3         MsgBox(0, "TCP Connect Error", $aError[$error], 0)         $socket = 0     EndIf     Return $socket EndFunc
    • kelso
      By kelso
      Hello Guru's,
       
      I'm trying to write an autoit script to select from the dropdown list as you see in the attached picture. 
      I read the help page for _IEFormElementOptionSelect, but I cannot grasp how to correlate that with the source code that I'm seeing. any suggestions?

    • Burgs
      By Burgs
      Hello,
        I'd like to be able to create variables 'on the fly' by reading in some data from an SQLite database.  Using this data i'd like to create variables.  The data would be separated by colons (":")...'colon delimited'.  I would perform a 'StringSplit' on the data to create arrays holding each colon separated value.  Ideally I could then use these strings to create variables from them...possible?
        I know it cannot be done just piecing a string together such as "var = "$_" & 'some string'"... 
        I think it might work using the 'Assign' command...and there is an 'Opt' option to 'ExpandVarStrings' which seems to indicate it is possible to include a "$" within a string...however the documentation is a bit spotty on that.
        Can anybody confirm that these might be the best practices to create variables dynamically?  ...Perhaps there is another method I'm not thinking of...?   I thank you in advance.  Regards.  
×