Sign in to follow this  
Followers 0
yousefsamy

Problem with [Do] loop

24 posts in this topic




Explain "isn't working".Is it throwing an error, is it not moving the mouse, is the script ending prematurely, what?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

1.

sugestion:

Until Not ($search = @error)

2.

question:

how you think in the following line

Until $search = Not @error

@error is returned from which function ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

yousefsamy,

Just one thread at a time please - merged. ;)

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

#6 ·  Posted (edited)

 

Here is my code, i don't know why isn't it working :

Do
    $search = PixelSearch(0,0,1023,767,0x0018C6)
    If $search = @error  Then Sleep(100)
Until $search = Not @error
MouseMove($search[0],$search[1],20)

after reading HelpFile I can guess: line 3 and 4 never happend

EDIT

line 3 never happend

and

line 4 always is true so the resutl is Exitloop

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites
Melba23

 

sorry for that i have a bad connection

Share this post


Link to post
Share on other sites
mLipok

but the loop ends itself when don't find the pixel ?

should do loop running until find the pixel ?

Share this post


Link to post
Share on other sites

Dim $aSearch[0]
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If Not IsArray($search) Then Sleep(100)
Until IsArray($aSearch)
MouseMove($aSearch[0],$aSearch[1],20)

If PixelSearch succeeds it returns an Array so you can try the above

If an error occurs $error is set to 1 so you could also do:

Dim $aSearch[0]
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If @error Then Sleep(100)
Until Not @Error
MouseMove($aSearch[0],$aSearch[1],20)

if 'Not @error' doesnt work try 'Until @error < 1'

Share this post


Link to post
Share on other sites

yousefsamy,

No problem - it happens to us all. :)

But - and I am getting really tired of asking you this same question over and over again - have you even looked at the Help file example for the function you are trying to use? :huh:

I think not, because the examples for _PixelSearch show exactly how to check for @error - and your code is nothing like it. What makes you think the return value should be the same as the @error macro? Go and look at the Help file example and try again. ;)

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

 

If an error occurs $error is set to 1 so you could also do:

Dim $aSearch[0]
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If @error Then Sleep(100)
Until Not @Error
MouseMove($aSearch[0],$aSearch[1],20)

if 'Not @error' doesnt work try 'Until @error < 1'

 

The sleep call will set @error = 0, so you will exit the loop unintentionally...do something like this:

Local $aSearch
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If @error Then Sleep(100)
Until IsArray($aSearch)
MouseMove($aSearch[0],$aSearch[1],20)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Like your first option, but with a correction.  You can't declare an array with 0 subscripts, syntactically.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

jdelaney,

 

You can't declare an array with 0 subscripts, syntactically

Do you mean that you cannot do this? :huh:

Dim $aSearch[0]
It is perfectly valid syntax - AutoIt has been able to use empty arrays since last summer, I remember rewriting the Array UDF to cope with them. ;)

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

Well , I shouldnt have made an empty array if I was doing an IsArray check also  soo ... :/ I didnt run any of the code, just shootin from the hip :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

The empty array doesn't matter, since it's checked at the end of the loop, and the function will set it to a non array if it fails.

Cool.  I'm still on the old version, where the array needs 1 subscript or more.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

where is the problem ,, i read the help file , but i do that with imagesearch() func ,, it works:

Local $aSearch

Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If $aSearch = 1 Then Sleep(100)
Until $aSearch <> 1
MouseMove($aSearch[0],$aSearch[1],20)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

PixelSearch will never return 1...it will return 0, if it doesn't find your pixel...stick with my example:

Local $aSearch
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    If @error Then Sleep(100)
Until IsArray($aSearch)
MouseMove($aSearch[0],$aSearch[1],20)

Or, you can do this:

Local $aSearch, $something
Do
    $aSearch = PixelSearch(0,0,1023,767,0x0018C6)
    $something = @error
    If $something Then Sleep(100)
Until Not $something
MouseMove($aSearch[0],$aSearch[1],20)
Edited by jdelaney
2 people like this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Return Values:
Success: a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y). 

Failure: sets the @error flag to 1 if the color is not found.

A failed PixelSearch will not set your variable($aSearch) to 1 it sets @error

@error = 1 on a failed PixelSearch

 

The only instance that $aSearch will be assigned a value is if your pixel is found.

Edited by Shane0000

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

jdelaney

why did you write this line ?

Local $aSearch, $something

and why if i type @error without put it in a variable didn't work ?

Edited by yousefsamy

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