TheMysteries

Setting a loopback with a statement

8 posts in this topic

Hey,

i'm trying to make a loopback function that if statement = Found it should keep clicking untill statement  = Not found
But I can't figure out how to make that line of text

This is what I got:
Local $iCount = 1
While FileExists("C:\window2.txt") = 0
    If $iCount = 50 Then 
        $iCount = 0
        ExitLoop
    EndIf
    $iCount += 1
WEnd
If $iCount Then
    ConsoleWrite("Found")
Else
    ConsoleWrite("NOT Found")
 EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try:

CheckFileExists('C:\Windows2.txt')
Func CheckFileExists($sString)
    For $i = 1 To 50
        If FileExists($sString) = 1 Then
            Return 'Found'
        EndIf
        Sleep(100)
    Next
    Return 'Not Found'
EndFunc

 

Edited by Subz
Used EndIf rather than EndFunc

Share this post


Link to post
Share on other sites
8 hours ago, Subz said:

Try:

CheckFileExists('C:\Windows2.txt')
Func CheckFileExists($sString)
    For $i = 1 To 50
        If FileExists($sString) = 1 Then
            Return 'Found'
        EndIf
        Sleep(100)
    Next
    Return 'Not Found'
EndIf

 

Nop doesn't work,
 

Local $iCount = 1
While FileExists("C:\window2.txt") = 0
    If $iCount = 50 Then
        $iCount = 0
        ExitLoop
    EndIf
    $iCount += 1
 WEnd
If $iCount Then
    ConsoleWrite("Found")
    MouseClick("left",836, 318, 1)
Else
    ConsoleWrite("NOT Found")

 EndIf

With my line of script, it clicks 1x if statement = 'found' but after that it doesn't check if statement = 'found' or not 'found' so it just stops after 1 single click. Dunno how to make a loopback of that oneo:)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Maybe I'm reading it incorrectly,  You have While FileExists("C:\Windows2.txt") = 0 keep looping , so If C:\Windows2.txt does exist it will exit the loop.  I did forget to put in the MouseClick, I should have written:

If CheckFileExists('C:\Windows2.txt') Then
    ConsoleWrite('Found' & @CRLF)
    MouseClick("left",836, 318, 1)
Else
    ConsoleWrite('Not Found' & @CRLF)
EndIf

Func CheckFileExists($sString)
    For $i = 1 To 50
        If FileExists($sString) = 1 Then Return True
        Sleep(100)
    Next
    Return False
EndFunc

If you didn't want to resuse the code as a function you could also just use:

For $i = 1 To 50
    If FileExists($sString) = 1 Then
        ConsoleWrite('Found' & @CRLF)
        MouseClick("left",836, 318, 1)
        ExitLoop
    EndIf
    Sleep(100)
Next
ConsoleWrite('Not Found' & @CRLF)

 

Edited by Subz
Used EndIf rather than EndFunc

Share this post


Link to post
Share on other sites

Sorry just realised, I used EndIf rather than EndFunc in my posts above, have now updated.

Share this post


Link to post
Share on other sites
15 minutes ago, Subz said:

Sorry just realised, I used EndIf rather than EndFunc in my posts above, have now updated.

If CheckFileExists('C:\Windows2.txt') Then
    ConsoleWrite('Found' & @CRLF)
    MouseClick("left",836, 318, 1)
Else
    ConsoleWrite('Not Found' & @CRLF)
EndIf

Func CheckFileExists($sString)
    For $i = 1 To 50
        If FileExists($sString) = 1 Then Return True
        EndIf
        Sleep(100)
    Next
    Return False
EndFunc

It works but now the script have to read the output (found) If the script answers > Found then continue clicking (delay 2sec) untill output > not found

Dunno if that is possibleo:)

Share this post


Link to post
Share on other sites

Sorry don't really understand, can you explain what you want to happen preferably step by step?

Do you mean:

CheckFileExists('C:\Windows2.txt')

Func CheckFileExists($sString)
    If FileExists($sString) = 1 Then
        While FileExists($sString)
            ConsoleWrite('Found' & @CRLF)
            MouseClick("left",836, 318, 1)
            Sleep(2000)
        WEnd
    EndIf
    ConsoleWrite('Not Found' & @CRLF)
EndFunc

 

Share this post


Link to post
Share on other sites
4 minutes ago, Subz said:

Sorry don't really understand, can you explain what you want to happen preferably step by step?

Do you mean:

CheckFileExists('C:\Windows2.txt')

Func CheckFileExists($sString)
    If FileExists($sString) = 1 Then
        While FileExists($sString)
            ConsoleWrite('Found' & @CRLF)
            MouseClick("left",836, 318, 1)
            Sleep(2000)
        WEnd
    EndIf
    ConsoleWrite('Not Found' & @CRLF)
EndFunc

 

:) That's what I was looking for. Thanks for the 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