Jump to content
Sign in to follow this  
EricL

simple Loop problems? why do my loops not end as expected?

Recommended Posts

Im sure this is noob question.. something basic I must be missing.

Here is my script. the window spy tells me there are two buttons i need to press. Install, and Exit.

it also shows me a hidden text "progress bar" is hidden when not installing, and in the text area when installing.

I found info in this form to get that text out using stringinstr. It seems to get stuck in the $bloop or $cloop part of my script.

im sure it something simple.. i been having alot of problems with loops using while or do functions.

Run( "\\server\cd$\accounting\custom\Full Client\xxxAppInstall.exe", "\\server\cd$\accounting\custom\Full Client\")
WinActivate("Application Installer")
WinwaitActive("Application Installer")
;
; ##GET Window Handle ID
$pHandle = WinGetHandle("")
$sText = WinGetText($pHandle)
;
WinActivate("Application Installer")
WinwaitActive("Application Installer")
;
; ##STart Install
controlclick("Application Installer","","ThunderRT6CommandButton4")
;
;##Start timer incase of error
$tloop = 1
while $tloop = 1
$Timebegin = TimerInit()
$TimeDif = TimerDiff($Timebegin)
if $TimeDif > 300000 Then
MsgBox(64, "Installation", "Install Failed. Contact your System Administrator.")
Exit
Else
;
; ##Look for progress bar to indicate Install is running
    $bloop = 1
    Do
    If StringInStr($sText,"Progress Bar") Then
    $bloop = 0
    Else
    $bloop = 1
    EndIf
    Until $bloop = 0
;
; ##Wait for progress bar to hide indicating install complete
    WinActivate("Application Installer")
    WinwaitActive("Application Installer")
    $cloop = 1
    Do
    If StringInStr($sText,"Progress Bar") Then
    $cloop = 1
    Else
    $cloop = 0
    EndIf
    Until $cloop = 0
;
; ##Exit Install
    controlclick("Application Installer","","ThunderRT6CommandButton3")
;EndIF
;$tloop = 0
;wend
;
; ##Confirm app closed
$endloop = 1
while $endloop = 1
$answer = ProcessWaitClose("xxxAppInstall.exe",300000)
if $answer = 0 Then
$endloop = 1
Else 
$endloop = 0
EndIF
wend
Edited by EricL

Share this post


Link to post
Share on other sites

Im sure this is noob question.. something basic I must be missing.

Here is my script. the window spy tells me there are two buttons i need to press. Install, and Exit.

it also shows me a hidden text "progress bar" is hidden when not installing, and in the text area when installing.

I found info in this form to get that text out using stringinstr. It seems to get stuck in the $bloop or $cloop part of my script.

im sure it something simple.. i been having alot of problems with loops using while or do functions.

Run( "\\server\cd$\accounting\custom\Full Client\xxxAppInstall.exe", "\\server\cd$\accounting\custom\Full Client\")

WinActivate("Application Installer")

WinwaitActive("Application Installer")

;

; ##GET Window Handle ID

$pHandle = WinGetHandle("")

$sText = WinGetText($pHandle)

;

WinActivate("Application Installer")

WinwaitActive("Application Installer")

;

; ##STart Install

controlclick("Application Installer","","ThunderRT6CommandButton4")

;

;##Start timer incase of error

$tloop = 1

while $tloop = 1

$Timebegin = TimerInit()

$TimeDif = TimerDiff($Timebegin)

if $TimeDif > 300000 Then

MsgBox(64, "Installation", "Install Failed. Contact your System Administrator.")

Exit

Else

;

; ##Look for progress bar to indicate Install is running

$bloop = 1

Do

If StringInStr($sText,"Progress Bar") Then

$bloop = 0

Else

$bloop = 1

EndIf

Until $bloop = 0

;

; ##Wait for progress bar to hide indicating install complete

WinActivate("Application Installer")

WinwaitActive("Application Installer")

$cloop = 1

Do

If StringInStr($sText,"Progress Bar") Then

$cloop = 1

Else

$cloop = 0

EndIf

Until $cloop = 0

;

; ##Exit Install

controlclick("Application Installer","","ThunderRT6CommandButton3")

;EndIF

;$tloop = 0

;wend

;

; ##Confirm app closed

$endloop = 1

while $endloop = 1

$answer = ProcessWaitClose("xxxAppInstall.exe",300000)

if $answer = 0 Then

$endloop = 1

Else

$endloop = 0

EndIF

wend

I think the main problem is that you are testing $stext for the inclusion of a string and looping if the string isn't included. However, if the string isn't included then it never will be because you don't update $stext.

Second point is that I think your loops are more complicated than they need to be and it's always a good idea to make things as simple as possible.

So where you have

Do
    If StringInStr($sText,"Progress Bar") Then
    $bloop = 0
    Else
    $bloop = 1
    EndIf
    Until $bloop = 0

you could have

while not StringInStr($sText,"Progress Bar") 
           $sText = WinGetText($pHandle);get current text
           sleep(20)
        wend

Finally, it's much easier for people to read your code if you enclose it in tags. Either AutoIt or Code; I prefer Code because there have been very many times when the AutoIt tags have caused problems. If you use Scite, then Tidy it first with Ctrl T. (Whoops, what happened to my "finally")

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I don't get why you use loops on ##Confirm app closed. You might loop too much. :)

I don't know why you whould use if else if you wait only for one condition to break the loops.

And finaly you have to update

$sText = WinGetText($pHandle)

in your loops, otherwise the value is not going to change...

Share this post


Link to post
Share on other sites

You guys rock. I just made my entire script about half the size, plus it works, which is a nice touch.

All those loops were making me loopy :)

I edited my post and used the code feature too ^_^

thanks for the tip

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  

×
×
  • Create New...