50M4

Stop sleep if ?

10 posts in this topic

#1 ·  Posted

Hey guys.

Im pretty new in that because  

Share this post


Link to post
Share on other sites



#2 ·  Posted

I'm sorry. 
I would like to know if i can stop sleep if something turns true?
 

Share this post


Link to post
Share on other sites

#3 ·  Posted

50M4,

Welcome to the AutoIt forums.

You can do this by using a series of small Sleeps and checking in between:

$iMaxDelay = 10000 ; 10 secs
$iActDelay = 0

While 1
    ; Minimum Sleep time
    Sleep(10) 
    ; Increase the actual delay
    $iActDelay += 10 
    ; If the test is true or the max delay is reached - exit the loop
    If $iTest = True Or $iActDelay >= $iMaxDelay Then ExitLoop
WEnd

There are several other ways to do it, but the basic principle is always the same.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Something like:

Local $i = 0
While 1
    If $i = 10 Then Exitloop
    Sleep(1000)
    $i += 1
Wend
MsgBox(48, "", "i: = " & $i)

Edit: Too slow Melba23 already answered :)

Hey Melba23

Edited by Subz

Share this post


Link to post
Share on other sites

#5 ·  Posted

Shouldn't this
If $iTest = True
be
If $bTest = True
?

:idiot:

Share this post


Link to post
Share on other sites

#6 ·  Posted

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

This days we can just  if something then ...

Using a meaningful variable name  would be better.

 

Saludos

Share this post


Link to post
Share on other sites

#8 ·  Posted

this days??? what about the old days? what do you use??? :lol::lol::lol:


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Was bored, maybe this is what you meant?

#include <String.au3>

HotKeySet("{F1}", SetName)

Global $sName = "Test"
Global $sBool = True
Global $iInt = -1
Global $dDouble = 0.0

ToolTip("$sName = " & $sName, 0, 0)

SleepUntil("sName = InunoTaishou", 100)

MsgBox("", $sName, "Name has been updated to " & $sName & ". Met condition needed and left sleep function")

ToolTip("$sBool = " & $sBool, 0, 0)

SleepUntil("$sBool <> True", 100)

MsgBox("", $sBool, "Bool has been updated to " & $sBool & ". Met condition needed and left sleep function")

ToolTip("$iInt = " & $iInt, 0, 0)

SleepUntil("$iInt > 0", 100)

MsgBox("", $iInt, "Int has been updated to " & $iInt & ". Met condition needed and left sleep function")

ToolTip("$dDouble = " & $dDouble, 0, 0)

SleepUntil("$dDouble = 99.99", 100)

MsgBox("", $dDouble, "Double has been updated to " & $dDouble & ". Met condition needed and left sleep function")

Func SetName()
    $sName = "InunoTaishou"
    HotKeySet("{F1}", SetBool)
EndFunc

Func SetBool()
    $sBool = False
    HotKeySet("{F1}", SetInt)
EndFunc

Func SetInt()
    $iInt = 100
    HotKeySet("{F1}", SetDouble)
EndFunc

Func SetDouble()
    $dDouble = 99.99
EndFunc

Func SleepUntil($sCondition, $iTime = 100)
    ; Comparison to use, check if Var = Val or Var <> Val in the while loop
    Local $sComparison = (StringInStr($sCondition, "=") ? "=" : StringInStr($sCondition, "<>") ? "<>" : _
                            StringInStr($sCondition, ">=") ? ">=" : StringInStr($sCondition, "<=") ? "<=" : _
                            StringInStr($sCondition, ">") ? ">" : StringInStr($sCondition, "<") ? "<" : "")

    ; Invalid operator supplied to compare Var to Val
    If ($sComparison = "") Then Return SetError(1, 0, False)

    ; Split the condition
    Local $aSplit = StringSplit($sCondition, $sComparison, $STR_NOCOUNT + $STR_ENTIRESPLIT)
    ; Variables used to hold the name of the Var to check and the value to check against
    Local $sVar = ""
    Local $sVal = ""

    ; Check that the condition supplied was a valid condition (i.e., $sVar = "String")
    If (UBound($aSplit) = 2) Then
        ; Get the var name, removing the '$' character so it can be used in Eval()
        ; and removing the trailing and leading spaces
        $sVar = StringReplace(StringStripWS($aSplit[0], $STR_STRIPLEADING + $STR_STRIPTRAILING), "$", "")

        ; Check that the variable is declared, if not return an error
        If (Not IsDeclared($sVar)) Then Return SetError(2, 0, False)

        ; Get the value, alost removing the trailing and leading
        $sVal = StringStripWS($aSplit[1], $STR_STRIPLEADING + $STR_STRIPTRAILING)
        If (IsNumber($sVal)) Then
            $sVal = Number($sVal)
        ElseIf ($sVal = "True") Then
            $sVal = True
        ElseIf ($sVal = "False") Then
            $sVal = False
        EndIf
    Else
        Return SetError(3, 0, False)
    EndIf

    ; Which comparison method to use?
    Switch ($sComparison)
        ; Keep sleeping until the Variable = the Val
        Case "="
            While (Eval($sVar) <> $sVal)
                Sleep($iTime)
            WEnd
        ; Keep sleeping until the Variable <> the Val
        Case "<>"
            While (Eval($sVar) = $sVal)
                Sleep($iTime)
            WEnd
        Case ">="
            While (Eval($sVar) <= $sVal)
                Sleep($iTime)
            WEnd
        Case "<="
            While (Eval($sVar) >= $sVal)
                Sleep($iTime)
            WEnd
        Case ">"
            While (Eval($sVar) < $sVal)
                Sleep($iTime)
            WEnd
        Case "<"
            While (Eval($sVar) > $sVal)
                Sleep($iTime)
            WEnd
    EndSwitch

    Return True
EndFunc

 

Edited by InunoTaishou
added >=, <=, >, and <; changed $sVal = "False" to $sval = False

Share this post


Link to post
Share on other sites

#10 ·  Posted

6 hours ago, 232showtime said:

this days??? what about the old days? what do you use??? :lol::lol::lol:

This:

CMP DX,	00

Saludos

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