Jump to content

AdLib & Timerdiff


 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
Link to comment
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. ;]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...