Jump to content

Multiple Select Case Problem {SOLVED}


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

×
×
  • Create New...