kor Posted January 18, 2011 Share Posted January 18, 2011 (edited) Is there a way to have a Do loop have an Or statement? Do x until y or z ? I have a loop that checks if a user exists in active directory. I want to keep looping until the user does exist, OR 5 minutes has passed. (i dont want the loop sitting there for hours stuck. If the user doesnt exist after 5 minutes skip and move on) Here is my current code. #include <AD.au3> _AD_Open() $username = "2" $userexists = "" Do $getattribute = _AD_GetObjectAttribute($username, "sAMAccountName") If _AD_ObjectExists($username, "sAMAccountName") Then msgbox(0, '', "exists") $userexists = True ElseIf @error = 1 Then msgbox(0, '', "does not exist") $userexists = False Else Exit ; dont know what to do EndIf Until $userexists = True msgbox(0, '', "end of loop") _AD_Close() I want to have an Until $userexists = True Or XXX Where XXX is a 5 minute timer Or what I can do is put a sleep statement in the above loop, for say 30 seconds. then just make the timer have 10 steps. So the loop only runs 10 times. But how can I do that? Edited January 18, 2011 by kor Link to comment Share on other sites More sharing options...
kor Posted January 18, 2011 Author Share Posted January 18, 2011 Thinking out loud. Does this look right? ; Open connection to AD _AD_Open() $username = "2" $userexists = "" $steps = 0 Do $getattribute = _AD_GetObjectAttribute($username, "sAMAccountName") If _AD_ObjectExists($username, "sAMAccountName") Then msgbox(0, '', "exists") $userexists = True ElseIf @error = 1 Then msgbox(0, '', "does not exist") $userexists = False $steps = $steps + 1 Else Exit ; dont know what to do EndIf Sleep(300) Until $userexists = True Or $steps = 10 msgbox(0, '', "end of loop") ; Close connection to AD _AD_Close() Link to comment Share on other sites More sharing options...
MvGulik Posted January 18, 2011 Share Posted January 18, 2011 Until $userexists Or $steps > 9- no need to test if a bool = true, only to get a other bool in its place.- even if you do use a step value of one(1) ... save coding style is to test for a upper/lower range value case, not just for a specific single value. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
ReaImDown Posted January 19, 2011 Share Posted January 19, 2011 Until $userexists Or $steps > 9- no need to test if a bool = true, only to get a other bool in its place.- even if you do use a step value of one(1) ... save coding style is to test for a upper/lower range value case, not just for a specific single value.^100% correct [u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now