Jump to content

[Solved] Loops and exit loops.


Recommended Posts

Hello everybody thanks for looking at my question.

I am trying to write a loop that will wait for a window to appear, and if it does not it will exit the script. If said window appears then it runs the script as normal.

As you can see, I've been looking through the forums for answers (below is an example form here). I am 90 percent done, and this is all the hold me back.

While True  
    While True
        ; this is where you do your stuff
        WinWait("!My-Cell")
        ; whatever your condition is to leave the loop
        
        If True Then
            ExitLoop
        EndIf
    WEnd
    $i = TimerInit()
    While TimerDiff($i)<6*10 ; 
    WEnd
WEnd

Full script below,

; #include <date.au3>
; !My-Cell
FileDelete("name.txt")


; S - Wait for window to apear  
;Look for Window for 10 Seconds if Not Found Exit Scirpt
If WinWait("!My-Cell", "", 10) = 0 Then Exit
WinActivate("!My-Cell")
; E - Wait for window to apear  

; S - Begin Timeer to query window for text.
$begin = TimerInit ()
        While 1
            $dif = TimerDiff ($begin)
            if $dif > 30000 then exitloop
            
; S - Send keys to pidgin to copy paste text to fiel and save           
Send("^l")
winactivate("!My-Cell")
Sleep(500)
Send("!c")
winactivate("!My-Cell")
Sleep(500)
Send("{RIGHT}")
winactivate("!My-Cell")
Sleep(500)
Send("{RIGHT}")
winactivate("!My-Cell")
Sleep(500)
send("{ENTER}")
winactivate("!My-Cell")
Sleep(500)
Send("{F6}")
winactivate("!My-Cell")
Sleep(500)
Send("^a")
winactivate("!My-Cell")
Sleep(500)
Send("^c")
winactivate("!My-Cell")
Sleep(500)
Send("^l")
 winactivate("!My-Cell")
Sleep(500)
; E - Send keys to pidgin to copy paste text to fiel and save   

; the & '@CRLF' adds a line break afer paste form clipboard
filewrite(".txt",clipget() & @CRLF)
sleep(10000)


#include <MsgBoxConstants.au3>
$AllText = FileRead(".txt")
$textToFind = ("successfully refreshed")
;If StringInStr($AllText,$textToFind) <> 0 then
If StringInStr($AllText,$textToFind) then
;it's there
MsgBox($MB_OK, "Crap", "Yes")
exitloop
else
;it isn't there
MsgBox($MB_OK, "Crap", "No")
Sleep(100)
endif

; E - Begin Timeer to query window for text.
wend

; Start read form text fiel and send to pidgin
#include <File.au3>
$file = "name.txt"
FileOpen($file, 0)
For $i = 1 to _FileCountLines($file)
$line = FileReadLine($file, $i)
Send($line)
Send("{ENTER}")
Sleep(5000)
Next
FileClose($file)
; end read form text fiel and send to pidgin

 

Edited by NoobieAutoitUser
Link to comment
Share on other sites

  • Developers

Specify a timeout parameter in WinWait() and test for the returned number as that will be 0 in case of timeout.

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

6 minutes ago, Jos said:

Specify a timeout parameter in WinWait() and test for the returned number as that will be 0 in case of timeout.

Jos

Yes, then the script runs after the time out. What I am trying to do is, when the script launches, it waits for a window to appear. If the window does not appear, it will exit the script.
Easier said then done I am finding out :)

Thanks for the input.

Link to comment
Share on other sites

  • Developers

Isn't what I said the answer?  WinWait() with a timeout parameter specified and test for the returned value? ;)

Jos

Edited by 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

  • Developers

No ...  you need to test for the returned value like:

$rc=WinWait("!My-Cell", "", 10000)
If not $rc Then exit

Easy ...right :)

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

  • Developers

Are you still having an issue or are you saying it is working now?
It will continue right away when a window with  "!My-Cell" in the title, else it will wait for 10000 seconds before exiting.

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

  • Developers

Well... it does work fine for me, so that means you do have that application active that contains the specified text in ta window title! 

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

Hi, and again thanks for your help,

I pasted the code into Scite, and ran the script. This is the output.

I am lost as to what is  not correct. I have tried so many 'For/if, Do/Until, Else' and I don't understand what is wrong. :)

Again, my goal is to (loop?) and wait for a window to appear, and then if it does not in 'x' seconds, exit script.

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "Q:\!Autoit\yjukukjjkl.au3" /UserParams    
+>20:37:08 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:Q:\!Autoit\yjukukjjkl.au3
+>20:37:08 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "Q:\!Autoit\yjukukjjkl.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

>Process failed to respond; forcing abrupt termination...
>Exit code: 1    Time: 5.385
; S - Wait for window to apear

$rc=WinWait("!My-Cell", "", 10000)
If not $rc Then exit

; E - Wait for window to apear
run("notepad")

 

Link to comment
Share on other sites

  • Developers

 

5 hours ago, NoobieAutoitUser said:

>Process failed to respond; forcing abrupt termination... >Exit code: 1    Time: 5.385

So what is the problem now as you clearly kill the script manually this time after some 5 seconds ...right?

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

'forcing abrupt termination' - that is me stopping the script?

I learn something new every day :)

Now this new version is stopped at 53 seconds, it should have stopped at 10  (give or take, and exited)? I am trying to use SCite, to see console errors, and maybe solve this.

So far the time out appears to do nothing, and notepad runs (not in SCite). In Scite nothing happens. '!My-Cell' is not open at any time.

I am trying to loop within Auotit and wait for a window to appear '!My-Cell'. Than run 'notepad'. Never is '!My-Cell'  window open, as I test the script to see what it does if the window is not there. I need it to time out (and not execute 'notepad' if '!My-Cell' does not appear.

Again thanks for trying. I am at these forums, as I am at my wits end. I have used example scripts form help, and used stuff form forums, but I am stuck.

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "Q:\!Autoit\hjhfdjhgjuytuytuntgdnjngh.au3" /UserParams    
+>09:40:57 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:Q:\!Autoit\hjhfdjhgjuytuytuntgdnjngh.au3
+>09:40:57 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "Q:\!Autoit\hjhfdjhgjuytuytuntgdnjngh.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

>Process failed to respond; forcing abrupt termination...
>Exit code: 1    Time: 53.79

 

Link to comment
Share on other sites

  • Developers

Ah ... think I finally understand what you are on about. You THINK that 10000 is in mSecs , so 10 seconds, but you need to read the helpfile again!

Quote

WinWait

Pauses execution of the script until the requested window exists.

WinWait ( "title" [, "text" [, timeout = 0]] )

Parameters

title The title/hWnd/class of the window to check. See Title special definition.
text [optional] The text of the window to check. Default is an empty string. See Text special definition.
timeout [optional] Timeout in seconds if the window does not exist. Default is 0 (no timeout).

Which I already had mentioned in post #8:

Quote

It will continue right away when a window with  "!My-Cell" in the title, else it will wait for 10000 seconds before exiting.

Jos

Edited by 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

39 minutes ago, Jos said:

Ah ... think I finally understand what you are on about. You THINK that 10000 is in mSecs , so 10 seconds, but you need to read the helpfile again!

Which I already had mentioned in post #8:

Jos

Very good,

I feel shamed as I did not catch that. ;)

I have been messing with this for days, and coping, pasting, and tweaking.

I assumed (no need to say what it stand for :) ) , that all is in Milli seconds.

Thanks so much for your patience. I feel a as  fool, but i know why now lol.

Works below.

; S - Wait for window to apear

$rc=WinWait("!My-Cell", "", 10)
If not $rc Then exit

; E - Wait for window to apear
run("notepad")

Edit : Can/how do I mark subject as solved?

Edited by NoobieAutoitUser
Afterthough reason for edit.
Link to comment
Share on other sites

Hi.

Edit your first post and add [Solved] to the beginning of the title.

Regards, Conrad

Edited by Simpel
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

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