Sign in to follow this  
Followers 0
oozma

AdLib & Timerdiff

9 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm trying to use an Adlib in a Timerdiff fuction. See below.

Global $set = 10000
Global $timer = TimerInit()

Switch TimerDiff($timer)
            Case 1 To $set
                AdlibEnable ("run",100) 
        EndSwitch

This is calling the function 'run' every 100ms, but the problem is it never ends. Even after 10,000ms it keeps going and going :D

Any way to stop this after 10 seconds and continue on with the rest of the script?

Edited by oozma

Share this post


Link to post
Share on other sites



I think it should be as followed:

AdlibEnable('Function', 100)
Sleep(10000)
AdlibDisabl3()

Share this post


Link to post
Share on other sites

oozma,

Try this:

; Start timer
$iBegin = TimerInit()
; Enable Adlib
AblibEnable("run", 100)
; Start loop which runs for 10 secs - during this loop function "run" is called every 100ms
While TimerDiff($iBegin) < 10000
    Sleep(100)  ; Very important or you use 100% CPU
WEnd
; Disable Adlib
AdlibDisable()
; Continue with the script

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

TY very much Melba and Authenticity.

Share this post


Link to post
Share on other sites

Unfortunately this didn't work, it still seems to loop the run function non-stop. :D

Share this post


Link to post
Share on other sites

Are you looping infinitely in the run Adlib function?

Share this post


Link to post
Share on other sites

This is the run function:

Func run()
    Send("J")
    sleep(100)
EndFunc

I assumed that would only execute once every 100ms until 10 seconds was reached.(Used Melba's from above)

Func type()
    Send("o")

$iBegin = TimerInit()
AdlibEnable("run", 100)
While TimerDiff($iBegin) < 10000
    Sleep(100) 
WEnd
AdlibDisable()

Send("C")
EndFunc


Func run()
    Send("J")
    sleep(100)
EndFunc

Share this post


Link to post
Share on other sites

Remove the Sleep call within the Adlib function.

Seems to me like a strange behavior:

Dim $iCounter = 1

AdlibEnable('SomeFunc', 50)
Sleep(500)
ConsoleWrite('Sleep over!!!' & @LF)
AdlibDisable()

Func SomeFunc()
    ConsoleWrite('Data' & $iCounter & @LF)
    $iCounter += 1
    Sleep(50)
    ConsoleWrite('Exiting Adlib' & $iCounter-1 & @LF)
EndFunc

So if you sleep more than or exactly the Adlib interval you're creating an infinite loop. ;]

Share this post


Link to post
Share on other sites

Perfect :D thanks.

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