Jump to content

do loop until 10 times


Go to solution Solved by PKG,

Recommended Posts

Hi all i an new to Autoit

i want to make a script that search for a pic and click it 

and repeate that for 10 times i had readed the help doc and some postes in the forums but no luck

the search and click itself is working but i cant get the loop to work

any ideas ?

#include <ImageSearch.au3>

$x = 0
$y = 0


$NUM = 0
While $NUM <= 10
   
Func start()
  
  Do
$Search = _ImageSearch('pic.bmp', 0, $x, $y, 0)

if $Search = 0 Then sleep (1000)
Until $Search = 1
If $Search = 1 Then
 MouseMove($x, $y,10)
 MouseClick("left", $x, $y, 1)
 EndIf
EndFunc


WEnd

when i run this code it give the following error

C:UsersAdministratorDownloadsImageSearchImageSearchtut.au3 (10) : ==> "While" statement has no matching "Wend" statement.:
Func start()
Edited by alexander95

Link to comment
Share on other sites

Which program do you try to automate?

Often there are faster and more reliable ways to do what you want to do.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Which program do you try to automate?

Often there are faster and more reliable ways to do what you want to do.

 

Because have a function inside a while wend loop.

It is not allowed.

 

Please guys just tell me how to fix it

i want to use this method 

thank u

Link to comment
Share on other sites

Alexander95,

this is no "I have a problem please solve it for me" forum. We ask questions for a reason. So please give us some answers and we will see how we can help you.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

alexander95,

JohnOne has told you what is wrong with your script; water asked for more information so he could perhaps offer some more focused help. And you complain? :o

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

 

this is no "I have a problem please solve it for me" forum. We ask questions for a reason. So please give us some answers and we will see how we can help you.

 

bro i want to learn this method 

there is no program i want to run on it i just wanna learn it

now i am seeing the autoit help doc i used all the loop methods but they are giving errors 

 

any ideas ?

Edited by alexander95

Link to comment
Share on other sites

alexander95,

JohnOne has told you what is wrong with your script; water asked for more information so he could perhaps offer some more focused help. And you complain? :o

M23

 

i am not complaining he is doing a favor for me and i am so thankful

but the thing is that i want to learn this type of automation 

thank u guys

Link to comment
Share on other sites

To learn AutoIt please have a look at the wiki. There is a tutorial section which is a good place to start.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You have 2 "ifs" and only one Endif. Either you put another EndIf in or you use ElseIf. (I think)

And your func starts in the middle of a loop.

 

i made them to i still have the following error

 

C:UsersAdministratorDownloadsImageSearchImageSearchtut.au3 (12) : ==> "Do" statement has no matching "Until" statement.:

Func start()

 

thank u for attempting to help me guys it is  so apriciated

Link to comment
Share on other sites

If you use "Do", you will have to have "Until" somewhere. Somewhere where AutoIT can find it, not hidden in another func or something.

Do <- This does the following command over and over again

Until <- Until a certain criteria is matched.

For example:

Do

   $variable = $variable + 1

Until $variable = 4

This would add 1 to the variable "Until" the variable equals 4.

I hope you understand what i mean.

Edited by bleh
Link to comment
Share on other sites

Hopefully this is clear as mud.

But I'll let you fill in the missing dots, etc.

While x < y

      .....

      Start()

      ......

Wend


Func Start()

     ........
     Do
         .....
         .....
     Until x

     ........

EndFunc

You really need to try some tutorials and carefully read the Help file though.

And probably put in the sleep that JohnOne mentioned.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Solution

Use this code.

#include <ImageSearch.au3>
$x = 0
$y = 0
$NUM = 0
While $NUM <= 10
    start()
    Sleep(10)
WEnd
Func start()
    Do
        $Search = _ImageSearch('pic.bmp', 0, $x, $y, 0)
        If $Search = 0 Then Sleep(1000)
    Until $Search = 1
    If $Search = 1 Then
        MouseMove($x, $y, 10)
        MouseClick("left", $x, $y, 1)
    EndIf
EndFunc   ;==>start
Link to comment
Share on other sites

You'll have to increment $NUM else it will never reach 10 and you will loop forever.

Also, just FYI, starting at 0 and looping until <= 10 is actually 11 rounds...assuming were talking integers here.

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

  • Recently Browsing   0 members

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