Teckx

IF Then Else, is it too long?

6 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

#4 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

#5 ·  Posted

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

#6 ·  Posted

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