Jump to content
Sign in to follow this  
Schoening

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

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

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

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

 

Share this post


Link to post
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 ...
 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

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

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

    • By AnRios
      Greetings friends!
      I have been searching the help file and Google, with no success, to find a way to validate images from a folder and mark them somehow in a spreadsheet.
      My context is: I made a code with the help of the community that captures images from SAP and saves them in a folder.  Now I'd like to identify which ones are black, if it's even possible. I read about PixelSearch, but did not get it to work. If someone could point me in the right direction, I'd appreciate it.
      The code I'm using:
      #include <File.au3> #include <ScreenCapture.au3> $x = InputBox("Title", "Amount of Images To Capture", "", "", 320, 150) If @error Then Exit $x = Number($x) $y = InputBox("Title", "Batch Name", "", "", 320, 150) If @error Then Exit $y = String($y) HotKeySet("{HOME}", "printscreen") Func printscreen() $FilePath =("C:\Fiscalizacao\Fotos"&"/") $FileName = $y & " - " $FileList = _FileListToArray($FilePath, $FileName & '*.jpg', 1) If Not IsArray($FileList) Then $FileName&= '1.jpg' Else $FileName &= $FileList[0] + 1 & '.jpg' EndIf _ScreenCapture_Capture($FilePath & "\" & $FileName, 354, 196, 673, 436) EndFunc HotKeySet("{BS}", "Terminate") Func Terminate() Exit 0 EndFunc For $i = 1 to $x Opt("WinTitleMatchMode",2) If NOT WinExists("Relatorio") Then MsgBox(0, "Atenção!", "Relatório do MOM deve estar aberto!") Call("Terminate") EndIf Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Sleep (250) Opt("WinTitleMatchMode",2) SendKeepActive("Relatorio") Send("{ENTER}") Sleep (1000) Send("{HOME}") Sleep (200) Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Send("{DOWN}") Next  
    • By plankton
      While IsArray(PixelSearch(100, 100, 300, 300, 0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","") Hi, above is my function that will execute ESC button when white color is present in specific area which is color 0xffffff.
      But how do I do the opposite like when white color is not present in that specific area? Like this below code which gives me error
       
      While IsArray(PixelSearch(100, 100, 300, 300, <>0xffffff))     Send("{ESC}")     Sleep(1000) WEnd  MsgBox(0,"Loop exited","")  
       
    • By plankton
      Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area.  Here is the example of my code. But it doesnt stop when color is disappeared.
       
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If Not  @Error Then
      While 1
      Sleep(1000)
      Send("{ESC}")
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If @Error Then Exitloop
       
    • By junichironakashima
      I have a windows 10 pc and Im trying to create an automatic solving in calculator with a simple worded question (example: What is 45 x 53 ?). thou I cant make the select...Case...EndSelect statement work, here is my code
      #include <AutoItConstants.au3> HotKeySet("{F4}", "ExitProg") Func ExitProg() Exit 0 EndFunc MouseClick($MOUSE_CLICK_LEFT, 417, 659, 2, 1) Send("^c") Func valData() $Chek = "What " If ClipGet() == $Chek Then Check() Else Do MouseClick($MOUSE_CLICK_LEFT, 417, 659, 2, 3) Send("^c") Sleep(500) Until ClipGet() == $Chek EndIf EndFunc Func Check() $Chek2 = "?" c1() c2() c3() c4() c5() c6() c7() Select Case c1() = $Chek2 ;two MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 474, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c2() = $Chek2 ;three MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 482, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c3() = $Chek2 ;four MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 487, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c4() = $Chek2 ;five MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 495, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c5() = $Chek2 ;six MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 495, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c6() = $Chek2 ;seven MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 509, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case c7() = $Chek2 ;eight MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("^v") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 509, 645, 2, 1) Send("^c") Sleep(150) MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1) Send("*") Send("^v") Send("{NUMPADENTER}") Case Else Exit EndSelect EndFunc Func c1() MouseClick($MOUSE_CLICK_LEFT, 485, 643, 2, 1) Send("^c") EndFunc Func c2() MouseClick($MOUSE_CLICK_LEFT, 493, 644, 2, 1) Send("^c") EndFunc Func c3() MouseClick($MOUSE_CLICK_LEFT, 498, 645, 2, 1) Send("^c") EndFunc Func c4() MouseClick($MOUSE_CLICK_LEFT, 508, 647, 2, 1) Send("^c") EndFunc Func c5() MouseClick($MOUSE_CLICK_LEFT, 514, 645, 2, 1) Send("^c") EndFunc Func c6() MouseClick($MOUSE_CLICK_LEFT, 523, 645, 2, 1) Send("^c") EndFunc Func c7() MouseClick($MOUSE_CLICK_LEFT, 530, 645, 2, 1) Send("^c") EndFunc valData() MouseClick($MOUSE_CLICK_LEFT, 1349, 196, 1, 1) ;clicking the answer in calc Send("^c") Send("{DEL}") MouseClick($MOUSE_CLICK_LEFT, 499, 706, 1, 1) Send("^v") Exit  
    • By BetaLeaf
      What is Rollbar?
      Rollbar provides real-time error alerting & debugging tools for developers. Learn more about it at https://rollbar.com/product/
      Demo: https://rollbar.com/demo/demo/
      Screenshot:
      Instructions: (RollbarTest.au3)
      ; Include RollbarSDK #include "RollbarSDK.au3" ;Turns on ConsoleWrite debugging override. ;Global $Rollbar_Debug=False ; Initialize RollbarSDK with the project's API key. ; Parameters ....: $__Rollbar_sToken - [Required] Go to https://rollbar.com/<User>/<ProjectName>/settings/access_tokens/ for your project. Use the token for post_server_item. _Rollbar_Init("eaa8464a4082eeabd9454465b8f0c0af") ; Write code that causes an error you want to catch, then call ; _Rollbar_Send ; Parameters ....: $__Rollbar_sErrorLevel - [Required] Must be one of the following values: Debug, Info, Warning, Error, Critical. ; $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_Send("Debug", "This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_Send("Warning", "This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_Send("Error", "This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_Send("Critical", "This is an critical message. If you received this, you were successful!", "Critical Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!") ;No Message ; Rollbar_Send's helper functions ; Parameters ....: $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_SendDebug("This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_SendInfo("This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_SendWarning("This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_SendError("This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_SendCritical("This is an critical message. If you received this, you were successful!", "Critical Message") ; Usable Example Local $sImportantFile = "C:\NOTAREALFILE_1234554321.txt" Switch FileExists($sImportantFile) Case True MsgBox(0, "Example Script", "An important file was found. Continuing...") Case Else _Rollbar_SendCritical('An important file was missing. Halting... File: "' & $sImportantFile & '"', 'Important file "' & $sImportantFile & '" is missing.') EndSwitch Notes: Please comment your feedback, advice, & suggestions below. While this is only a proof of concept, I will expand its feature set for everyone to use. 
      Right now, it is fully functional but not tested in production.
       
       
      Changelog:
      RollbarSDK.au3
      RollbarTest.au3
      v0.2
       
      v0.1.1
       
×
×
  • Create New...