Been using autoit here for for about 6 months. I am a software dev, and it is very useful to help automate tasks for work so I can spend my time accomplishing other goals but I believe I have come across a pretty serious bug in the way Autoit executes scripts.
This in my experience has applied to while and for loops but I believe it extends to any loops inside of loops. The easiest example of this bug I can explain is on for loops
For $i = 1 To 8
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
if $oInput.value = "SOMEVALUE" Then
$ButtonObject = $oInput
EndIf
Next
MyFunction( $oInput)
Next
this is actual code I have been working on but I changed a few names of things to make it very generic. So we would expect the initial For loop to execute 8 times now, and inside each of those 8 runs to find the object on the webpage I am looking for. But the issue is that my loop only runs 4 times? So I jumped it up 1 to 16 on my bounds on the outermost For loop and it runs 8 times. Great so it works right? Well it seems to me that at some point when the token "Next" is encountered that it must also for some reason be increasing my outermost For loop counter when it should not. But I know for a fact that isn't really the case since it would have to step through the innermost loop about 30 times (lots of elements on the IE page,) so it only seems to be increasing the outermost For loop counter upon exiting the the innermost loop. Sounds like something with the looping stack isn't working correctly.
Here is the example of the while loops that didn't work correctly, now I will say this isn't copied and pasted from my code as I undid the work since it didn't work and I had a theory loops had an issue but wasn't able to observe it correctly until now. The code will be very very psuedo code to make reading easier
setupProgramData()
while(1)
sleepUntilProgramStartTime($startTime) <-- this was initially a while loop also but would stay inside the loop until I made it a method
dostuff()
$rs = getSomeSQLRecords()
While $rs.EOF = False
doStuffWithSQLData($rs)
WEnd
cleanup()
WEnd
Now what happened here if I remember correctly, whenever the WEnd was encountered leaving the innermost While Loop the software would break. I cannot recall exactly what happened, but with msgbox outputs and spitting out values I could see then things went south. It ran perfectly before I tried to implement this idea of never stop running and just begin again when it was the proper time by using the outermost while loop. I did test just getting a message box at the right time and it also did work; so I know by itself the outermost loop did also work. Just when nesting loops Autoit becomes not very happy.
This issue doesn't seem to arise when I have a loop inside of a function/method and call said function/method inside of that loop. It just seems to be an issue when loops are nested within the same function/method. If anyone has any input or feedback for me I would greatly appreciate it, or to at least know if this is a known issue.
This in my experience has applied to while and for loops but I believe it extends to any loops inside of loops. The easiest example of this bug I can explain is on for loops
For $i = 1 To 8
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
if $oInput.value = "SOMEVALUE" Then
$ButtonObject = $oInput
EndIf
Next
MyFunction( $oInput)
Next
this is actual code I have been working on but I changed a few names of things to make it very generic. So we would expect the initial For loop to execute 8 times now, and inside each of those 8 runs to find the object on the webpage I am looking for. But the issue is that my loop only runs 4 times? So I jumped it up 1 to 16 on my bounds on the outermost For loop and it runs 8 times. Great so it works right? Well it seems to me that at some point when the token "Next" is encountered that it must also for some reason be increasing my outermost For loop counter when it should not. But I know for a fact that isn't really the case since it would have to step through the innermost loop about 30 times (lots of elements on the IE page,) so it only seems to be increasing the outermost For loop counter upon exiting the the innermost loop. Sounds like something with the looping stack isn't working correctly.
Here is the example of the while loops that didn't work correctly, now I will say this isn't copied and pasted from my code as I undid the work since it didn't work and I had a theory loops had an issue but wasn't able to observe it correctly until now. The code will be very very psuedo code to make reading easier
setupProgramData()
while(1)
sleepUntilProgramStartTime($startTime) <-- this was initially a while loop also but would stay inside the loop until I made it a method
dostuff()
$rs = getSomeSQLRecords()
While $rs.EOF = False
doStuffWithSQLData($rs)
WEnd
cleanup()
WEnd
Now what happened here if I remember correctly, whenever the WEnd was encountered leaving the innermost While Loop the software would break. I cannot recall exactly what happened, but with msgbox outputs and spitting out values I could see then things went south. It ran perfectly before I tried to implement this idea of never stop running and just begin again when it was the proper time by using the outermost while loop. I did test just getting a message box at the right time and it also did work; so I know by itself the outermost loop did also work. Just when nesting loops Autoit becomes not very happy.
This issue doesn't seem to arise when I have a loop inside of a function/method and call said function/method inside of that loop. It just seems to be an issue when loops are nested within the same function/method. If anyone has any input or feedback for me I would greatly appreciate it, or to at least know if this is a known issue.