Jump to content
Teckx

IF Then Else, is it too long?

Recommended Posts

Teckx

Hello

 

I have an idea on a script I want to run for a daily task I perform.

My goal is to have the script do an image search and if it finds it then perform additional steps, if it doesn't present me with a message box

most of the IF THEN ELSE ENDIF samples I see are very short

example

IF variable THEN etc

Else etc

ENDIF

 

What I have planned would make that IF line super long

So far I have this for my image search . Is there a way I can change this so it isn't searching for the image forever and eventually gives up after say 5 seconds?

 

do
$result = _ImageSearch("C:\Users\BBH8655\Desktop\ImageSearch2015\dc2x.png",1,$x1,$y1,0)
until $result = 1;
if $result=1 Then
    MouseMove($x1,$y1,3)
    MouseClick("left", $x1,$y1, 1)


EndIf

Share this post


Link to post
Share on other sites
water

Use TimerInit before the Do statement and check the elapsed time inside the loop with TimerDiff.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Teckx

okay so why isn't this working? No error, but the script never stops and waits for that image to show up. I figured the Else would have kicked in and closed the script down

 


do
$result = _ImageSearch("C:\Users\Desktop\ImageSearch2015\completed.png",1,$x1,$y1,0)
until $result = 1;
if $result=1 Then
    MouseMove($x1,$y1,3)
    MouseClick("left", $x1,$y1, 2)
Else
 $init = TimerInit()
While 1
    If TimerDiff($init) > 3000 Then Exit
    Sleep(100)
WEnd
EndIf
 

Edited by Teckx

Share this post


Link to post
Share on other sites
Jos

Ok...  Think a lityle more on this logic you posted:

Do
    $result = _ImageSearch("C:\Users\Desktop\ImageSearch2015\completed.png", 1, $x1, $y1, 0)
Until $result = 1 ;
If $result = 1 Then
    MouseMove($x1, $y1, 3)
    MouseClick("left", $x1, $y1, 2)
Else
    $init = TimerInit()
    While 1
        If TimerDiff($init) > 3000 Then Exit
        Sleep(100)
    WEnd
EndIf

Do you think the If on line 4 will ever be false?

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
VIP

Because "Do Until"! Only exit loop when Unti(true)!
 

Global $x1, $y1, $init = TimerInit()
While 1
    Local $result = _ImageSearch("C:\Users\Desktop\ImageSearch2015\completed.png", 1, $x1, $y1, 0)
    If $result = 1 Then
        ConsoleWrite("+Found IMG" & @CRLF)
        MouseMove($x1, $y1, 3)
        MouseClick("left", $x1, $y1, 2)
    EndIf
    If TimerDiff($init) > 3000 Then Exit ConsoleWrite("! IMG is not found!" & @CRLF)
    Sleep(100)
WEnd

 


Regards,
 

Share this post


Link to post
Share on other sites
Teckx

Thanks I figured that out as I was driving home I made a loop and the result has to be true.  Doh 

 

thanks for thr help

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

×