Jump to content

IF Then Else, is it too long?


Recommended Posts

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

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

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
Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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,
 

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...