Sign in to follow this  
Followers 0
litlmike

'If Not' nested in While Loop

11 posts in this topic

#1 ·  Posted (edited)

Question:

Are we not able to put in an "If Not" Statement in a While loop? I cannot get the If Not to evaluate in this while loop.

I am putting a condensed version of the script. If you need more of the code, let me know.

*NOTE* this is an error checking script. So it checks for the error, and if it doesn't work, it loops until success.

While $ControlFocusReturn <> 1
            If Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEndoÝ÷ Ù»«HjkkÊ)à¶ËðèþïÛZ¥{Mú
í®E¡Ë¬Eën®x¬l¹Ç²Çîê®j[hÖØ^Ú-+,¶çß!ø­Éè¶Ø^q«¶­Ó~¢{k¢Qhrëªæ¥²Ø^
í®HMúëm¢uíé¢{k¢Qhrë(Ø^
í®HMúëm¢uÚÛazp¨Úèg­.²í«pwhÂÚç$ûayúºÈ¬¢}7è­¶×N§È§ÛÚÇÑzËh~Ø^
^jëh×6Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            If Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFunc
Edited by litlmike

Share this post


Link to post
Share on other sites



Well the way you have it, it never checks the ControlGetFocus() if it wasn't true to begin with.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Well the way you have it, it never checks the ControlGetFocus() if it wasn't true to begin with.

Sorry for being misleading, I should have posted more of the code originally. Unless I am misunderstanding you, I think that it already was doing that.

However, shouldn't it still evaluate the If Not either way? As long as the ControlGetFocus ($ControlFocus) is not equal to $ButtonX, it still should evaluate the statement, right?

Share this post


Link to post
Share on other sites

I don't really understand what you're trying to do, but what about "If $ControlFocus <> $ButtonX"?

Share this post


Link to post
Share on other sites

I always do...

If Not ($ControlFocus = $ButtonX) Then
Thanks, I made the change and I will start use this as standard practice. Sadly, this did not resolve the issue for me.

Any ideas why the 'If Not' will not run? The loop engages, but not the 'If Not'.

*NOTE* this is an error checking script. So it check for the error, and if it doesn't work, it loops until sucess.

Share this post


Link to post
Share on other sites

Question:

Are we not able to put in an "If Not" Statement in a While loop? I cannot get the If Not to evaluate in this while loop.

I am putting a condensed version of the script. If you need more of the code, let me know.

*NOTE* this is an error checking script. So it checks for the error, and if it doesn't work, it loops until success.

While $ControlFocusReturn <> 1
            If Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEndoÝ÷ Ù»«HjkkÊ)à¶ËðèþïÛZ¥{Mú
í®E¡Ë¬Eën®x¬l¹Ç²Çîê®j[hÖØ^Ú-+,¶çß!ø­Éè¶Ø^q«¶­Ó~¢{k¢Qhrëªæ¥²Ø^
í®HMúëm¢uíé¢{k¢Qhrë(Ø^
í®HMúëm¢uÚÛazp¨Úèg­.²í«pwhÂÚç$ûayúºÈ¬¢}7è­¶×N§È§ÛÚÇÑzËh~Ø^
^jëh×6Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            If Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFunc
if at the entry of the while loop $ControlFocus=$ButtonX and $ControlFocusReturn <> 1, the while loop will be infinite and the if not condition never met.

You have to put an else inside the loop to solve this issue

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

if at the entry of the while loop $ControlFocus=$ButtonX and $ControlFocusReturn <> 1, the while loop will be infinite and the if not condition never met.

You have to put an else inside the loop to solve this issue

Interesting....

So then should it be this:

Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            ElseIf Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFunc
Edited by litlmike

Share this post


Link to post
Share on other sites

Interesting....

So then should it be this:

Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            ElseIf Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFuncoÝ÷ Ûú®¢×«wöÉèµÊ+­ç-[!óh·­Ú|­Ê·ö·Å©©è¬)±¬¢®¶­s`¢b33c·Ò¢b33c·Ò¥vÆR¢bæ÷Bb33c·Òb33c·FVà¢×6t&÷Âb33²b33²Âb33²b33²¢æ÷@¥tVæ@
Do you think you will ever see the MsgBox? There's no condition to ever change the $y or the $x, just like in yours, you never ever check $ControlFocus so why should it keep going in there? Was it ($controlfocus) true before the loop or false? etc....

My suggestion would be to post a replica of your situation rather than us guessing to appease you. You would have had your answer the very first post more than likely, and been several hours on your way.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Interesting....

So then should it be this:

Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            ElseIf Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFuncoÝ÷ Ø òÁ¬¢·lZ¦º ­©¦x)­§-Ç­¢×¬µ©Þ«b½ç(Ø­Ú²+wöɨ­çb}øº[m¡©Ú+اµéeyËnjYr²­ßÛzÛ^®Ú0®+^jëh×6Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            If $ControlFocus = $ButtonX Then 
                ;****** put the code here
            else
               $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
               $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFunc

Share this post


Link to post
Share on other sites
Func ErrorCheck_Check_Activity ()
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    $ControlFocus = ControlGetFocus ("Clear Activity")
            
        While $ControlFocusReturn <> 1
            If Not $ControlFocus = $ButtonX Then 
            $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
            $ControlFocus = ControlGetFocus ("Clear Activity")
            EndIf
        WEnd
        
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFuncoÝ÷ Ûú®¢×¥zÝý²Úò¶§uê쵩Ý­ʰj{m¡Ú5r§ëayúºÊ'Ó~ºÛh} zÛayÊ'¶º%Ü!ÈajËayúºÉh¢!W©àxZºÉè¶ËqçûayúºÈ¬h»­¶×­çhÕ©ÝÙéÝ)Ë.쨹ªÞjZÞiܨMúnëm¢uðéÞ׫x-çîËb¢|!jØZ¦§°ay"·lmë-¶hjëh×6Func ErrorCheck_Check_Activity ()
    $ControlFocus=ControlGetFocus ("Clear Activity")
    While $ControlFocus <> $ButtonX
        if ControlFocus ("Clear Activity", "", $ButtonX)<>1 then
           ; tell the error :  msgBox(0,"","Error !")
        else
           $ControlFocus = ControlGetFocus ("Clear Activity")
        endif
     Wend
 
    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
EndFunc

Share this post


Link to post
Share on other sites

My apologies if ive not understood what you intend to do but I dont see the point of this code.

the code below should in theory do the same thing. It simply checks if it set buttonx as the focused control and tries again if it didnt. is that what your looking for?

Func ErrorCheck_Check_Activity ()

    Do 
    $ControlFocusReturn = ControlFocus ("Clear Activity", "", $ButtonX)
    Until $ControlFocusReturn=1

    ControlCommand ("Clear Activity", "", $ButtonX , "Check", "")
    
EndFunc

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