Jump to content

Setting a loopback with a statement


Recommended Posts

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

Link to comment
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:)

Link to comment
Share on other sites

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
Link to comment
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:)

Link to comment
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

 

Link to comment
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! 

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