Sign in to follow this  
Followers 0
Mossa

Strange looping

11 posts in this topic

Hello,

i got a realy big problem i can't solve by myself.

Below is the code i have, there are two debug msgboxes telling me the loop count.

It looks like the script is hopping around and not running through the loops like i coded them. I can't understand it and there is no debug mode. I am near to believe it's a autoit bug or i'm outside the limitations or something like that.

Please have a look at it, possibly you see my mistake.

Thanks in advance,

Mossa

#include <File.au3>

; ----------------------------------------------------------------------------
; Set up our defaults
; ----------------------------------------------------------------------------

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("RunErrorsFatal", 1)
AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("WinTitleMatchMode", 3)
AutoItSetOption("WinSearchChildren", 1)


; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

dim $answer
dim $usrfile, $user, $actualuser
dim $zeitfile
dim $zeitzeile
dim $i, $y
dim $zeitlinecount, $userlinecount
dim $logfile


;$answer = MsgBox(4, "DDS-Skript", "Soll das Skript starten?")
;if $answer = "6" then
    
    Run("cmd.exe /C G:\dds\tempo\TEMPO.exe", "", @SW_MINIMIZE)
    
    $userlinecount = _FileCountLines( @ScriptDir & "\User.txt")
    
    For $y = 1 to $userlinecount Step 1
        
        if $y > 1 then
            Send("!da")
        endif
        
        $actualuser = getUser($y)
        WinWaitActive("Anmelden")
        ControlSend("Anmelden", "", "Edit2", "{RIGHT 10}{BS 10}"&$actualuser)
        ControlSend("Anmelden", "", "Edit3", $actualuser&"{TAB}{ENTER}")
        
        WinWaitActive("TEMPO")
        ControlClick ( "TEMPO", "", "Button1")
        
        WinSetState("DDS Tempo", "", @SW_MAXIMIZE)
        
        Send("!bz")
        WinWaitActive("TEMPO")
        ControlClick ( "TEMPO", "", "Button1")
        Sleep(1000)
        
    ;setListen()
        
        $zeitlinecount = _FileCountLines( @ScriptDir & "\Zeit_"&$actualuser&".txt")
        For $i = 1 to $zeitlinecount Step 1
            MsgBox(0,"for count", $i)              ; DEBUG MsgBox
            Send("!bn")
            $zeitzeile = getZeitZeile($i)
            if $zeitzeile[1] = "r" then
                Send($zeitzeile[1]&"{TAB}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    WinWaitActive("Ungültige Eingabe")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[2]&"{TAB}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    WinWaitActive("Ungültige Eingabe")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[3]&"{TAB}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[4]&"{TAB}")
                MsgBox(0,"bla123", WinExists("Ungültige Eingabe"))   ; DEBUG MsgBox
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    WinActivate("Ungültige Eingabe")
                    WinWaitActive("Ungültige Eingabe")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[5]&"{TAB 3}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[9]&"{TAB}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
            elseif $zeitzeile[1] = "n" then
                Send($zeitzeile[1]&"{TAB 5}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[6]&"{TAB 2}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
                Send($zeitzeile[9]&"{TAB}")
                If WinExists("Ungültige Eingabe") = 1 Then
                    writeToLog($actualuser, "FAILED")
                    Send("{ENTER}")
                    ExitLoop
                EndIf
            endif
        Next
        
        
        Sleep(2000)
        Send("!dl")
        WinWaitActive("TEMPO")
        ControlClick ( "TEMPO", "", "Button1")
        Send("!dm")
        WinWaitActive("TEMPO")
        ControlClick ( "TEMPO", "", "Button1")
        writeToLog($actualuser, "PASSED")
    Next    
    WinClose("DDS Tempo")
;endif



Func writeToLog($actualuser, $pass)
    $logfile = FileOpen( @ScriptDir&"\"&@YEAR&@MON&@MDAY&"_log.txt", 1)
    FileWriteLine($logfile, $actualuser&": "&$pass)
EndFunc

Func setListen()
    Send("!OE")
    WinWaitActive("Eigene Listen")
    Send("{TAB}{TAB}{ENTER}")
    Sleep(1000)
    Send("+{TAB}+{TAB}+{TAB}{RIGHT}{RIGHT}")
    Sleep(1000)
    Send("{TAB}{TAB}{TAB}{ENTER}")
    Sleep(1000)
    ControlClick("Eigene Listen", "", "Button5")
EndFunc

Func getUser($y)
    $usrfile = FileOpen(@ScriptDir & "\User.txt", 0)
    $user = FileReadLine($usrfile, $y)
;FileClose($usrfile)
    return $user    
EndFunc

Func getZeitZeile($i)
    $zeitfile = FileOpen(@ScriptDir & "\Zeit_"&$actualuser&".txt", 0)
    $zeitzeile = FileReadLine($zeitfile, $i)
    $zeitzeile = StringSplit($zeitzeile, ";")
;FileClose($usrfile)
    return $zeitzeile
EndFunc

Share this post


Link to post
Share on other sites



Do you realize that the ExitLoop really exits the second for ...next loop?

0024  +-For $y = 1 To $userlinecount Step 1
0025  |  +-If $y > 1 Then
0026  |  |    Send("!da")
0027  |  +-EndIf
0028  |    $actualuser = getUser($y)
0029  |    WinWaitActive("Anmelden")
0030  |    ControlSend("Anmelden", "", "Edit2", "{RIGHT 10}{BS 10}" & $actualuser)
0031  |    ControlSend("Anmelden", "", "Edit3", $actualuser & "{TAB}{ENTER}")
0032  |    WinWaitActive("TEMPO")
0033  |    ControlClick("TEMPO", "", "Button1")
0034  |    WinSetState("DDS Tempo", "", @SW_MAXIMIZE)
0035  |    Send("!bz")
0036  |    WinWaitActive("TEMPO")
0037  |    ControlClick("TEMPO", "", "Button1")
0038  |    Sleep(1000)
0039  |   ;setListen()
0040  |    $zeitlinecount = _FileCountLines (@ScriptDir & "\Zeit_" & $actualuser & ".txt")
0041  |  +-For $i = 1 To $zeitlinecount Step 1
0042  |  |    MsgBox(0, "for count", $i)             ; DEBUG MsgBox
0043  |  |    Send("!bn")
0044  |  |    $zeitzeile = getZeitZeile($i)
0045  |  |  +-If $zeitzeile[1] = "r" Then
0046  |  |  |    Send($zeitzeile[1] & "{TAB}")
0047  |  |  |  +-If WinExists("Ungültige Eingabe") = 1 Then
0048  |  |  |  |    writeToLog($actualuser, "FAILED")
0049  |  |  |  |    WinWaitActive("Ungültige Eingabe")
0050  |  |  |  |    Send("{ENTER}")
0051  | <========== ExitLoop
0052  |  |  |  +-EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Do you realize that the ExitLoop really exits the second for ...next loop?

Why would it do that? The help file clearly states that ExitLoop without the optional [level] parameter will only break out of the current loop.

ExitLoop [level]

Parameters

level [optional] The number of levels of loop to break out of. The default is 1 (meaning the current loop).


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

Why would it do that? The help file clearly states that ExitLoop without the optional [level] parameter will only break out of the current loop.

<{POST_SNAPBACK}>

Correct ... thus goes back to the first For...Next

What am I missing ? :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Of course you are right JdeB.

Exitloop leaves only Do/Until, While/Wend, For/Next loops.

If/Then/Else is not a loop.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Are you saying then that an "ExitLoop 2" would exit only the inner For/Next loop? If so, that seems ass-backwards to me.

Edited by Klaatu

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

DUH... No, he is not. He means that exitloop exits the inner loop exitloop 2 exits the top loop, but you never used exitloop 2.


Who else would I be?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Are you saying then that an "ExitLoop 2" would exit only the inner For/Next loop? If so, that seems ass-backwards to me.

<{POST_SNAPBACK}>

@Klaatu, all i am saying is that the ExitLoop exits the inner for..next loop ( which is the second For...Next statements ) i thought the first post i made explained that very nicely :) but it seems to have confused you for some reason.

I have the impression that Mossa wants to end the IF...EndIF with and ExitLoop but am not sure ... Only Mossa will know :)

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yes, I think we were talking about the same thing, only differently. I took it to mean when you said "Do you realize that the ExitLoop really exits the second for ...next loop?", that you meant the top loop, meaning the second For loop away from the ExitLoop. Sorry for the confusion.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

Yes, I think we were talking about the same thing, only differently. I took it to mean when you said "Do you realize that the ExitLoop really exits the second for ...next loop?", that you meant the top loop, meaning the second For loop away from the ExitLoop. Sorry for the confusion.

<{POST_SNAPBACK}>

No problem.... we just gave Mossa a nice long thread to read through.... :)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

No problem.... we just  gave Mossa a nice long thread to read through....  :)

<{POST_SNAPBACK}>

That's right. Thanks for that.

For the nice discussion a note: I want to exit the inner for...next loop with ExitLoop.

But after sleeping a night thinking about the problem, i tried putting more sleep statements in it. And it worked! ;) The problem was that autoit is too fast for the application i am dealing with. That's where the strange looping behaviour come from. :)

Good to know.

Thank you all for reading my post and trying to help me.

best,

Mossa

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
Sign in to follow this  
Followers 0