Sign in to follow this  
Followers 0
SoulA

AdlibEnable Question

12 posts in this topic

Is it possible to have more than one AdlibEnable in a script?

For example AdlibEnable("Function1" 10) and AdlibEnable("Function2" 30)

Share this post


Link to post
Share on other sites



Is it possible to have more than one AdlibEnable in a script?

For example AdlibEnable("Function1" 10) and AdlibEnable("Function2" 30)

It's not possible, but do a search for "_AdlibManager".

Or look at the API Timer functions.


[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

#3 ·  Posted (edited)

You can possibly do something like this:

AdlibEnable("Function1",500)

Func Function1()
;your function code goes here
AdlibDisable()
AdlibEnable("Function2",500)
EndFunc

Func Function2()
;your function code goes here
AdlibDisable()
AdlibEnable("Function1",500)
EndFunc

This should do the equivalent of having more than one Adlib Functions.

Edited by ankitstr

[topic="80940"] AutoScript Creator, Script to automate anything![/topic]

Share this post


Link to post
Share on other sites

You can possibly do something like this:

AdlibEnable("Function1",500)

Func Function1()
;your function code goes here
AdlibDisable()
AdlibEnable("Function2",500)
EndFunc

Func Function2()
;your function code goes here
AdlibDisable()
AdlibEnable("Function1",500)
EndFunc

This should do the equivalent of having more than one Adlib Functions.

this is resourceful

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

this is resourceful

Its nice to know that I could be resourceful too :)

Edited by ankitstr

[topic="80940"] AutoScript Creator, Script to automate anything![/topic]

Share this post


Link to post
Share on other sites

I didn't say that it isn't meaningless


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

What I really wanted was to adlibs executing at different times. ankistr's method didn't really provide even though it was "resourceful" lol.

So in the end I had one adlib and used TimerInit and in the function called by adlib I had it do whatever I wanted every 10ms and did TimerDiff() to check if it was time to do what I wanted to do every 10 seconds. It works... or so I think even though two adlibs would have been much easier.

Edited by SoulA

Share this post


Link to post
Share on other sites

This is one way to have multiple timed actions...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Dim $Header_1 = "Machine"
Dim $Header_2 = "Line"
Dim $Header_3 = "Office"
Dim $Name, $TotalTime, $Unit, $count
Dim $TimerActive_[50], $Label_[50], $TButton_[50], $SButton_[50], $Input_[50], $Label_[50]
Dim $Time_[50], $Timer_[50], $sTime_[50], $xk, $ck, $tk, $pk, $Left = 0, $Top = 20, $X, $Radx, $Rad_[11]

$Today_File = @MON & "-" & @MDAY & "-" & @YEAR & ".txt"
$Log = FileOpen($Today_File, 1)
FileWriteLine($Log, "Logfile started: " & _DateTimeFormat( _NowCalc(), 0) & @CRLF & @CRLF)
FileClose($Log)

$Toy_Logo = @TempDir & "\Toy2-logo.jpg"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box2-jpg.jpg", $Toy_Logo)
$Toy_Banner = @TempDir & "\Toy-banr.jpg"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-jpg.jpg", $Toy_Banner)
$Logo_icon = @TempDir & "\Toy-Icon.ico"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-Icon.ico", $Logo_icon)

Setup()

AdlibEnable("AllTimers", 500)

GUICreate("   Toy BOX  -  Multi-Station-Timer", (110 * $pk), 470)
GUISetIcon($Logo_icon)


;Top computer label
GUICtrlCreateLabel($Header_1 & "s", 0, 0, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

;Middle phones label
GUICtrlCreateLabel($Header_2 & "s", 0, 220, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

;Bottom PC label
GUICtrlCreateLabel($Header_3 & "s", 0, 340, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

For $X = 1 To $pk
; row 1
    GUICtrlCreateLabel($Header_1 & " " & $X, $Left, $Top, 100, 20, $SS_CENTER)
    $Label_[$X] = GUICtrlCreateLabel("", $Left, $Top + 20, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[$X], 16)
    GUICtrlSetData($Label_[$X], "00:00:00")
    $TButton_[$X] = GUICtrlCreateButton("Start", $Left, $Top + 50, 50, 20)
    $SButton_[$X] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 50, 50, 20)
    $Input_[$X] = GUICtrlCreateInput("", $Left, $Top + 70, 100, 20, 0x1000)
   ;MsgBox(0,$pk, $Radx & @CRLF & $count)
; row 2
    GUICtrlCreateLabel($Header_1 & " " & ($X + (($count +1)* .25)), $Left, $Top + 100, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .25))] = GUICtrlCreateLabel("", $Left, $Top + 120, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .25))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .25))], "00:00:00")
    $TButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Start", $Left, $Top + 150, 50, 20)
    $SButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 150, 50, 20)
    $Input_[($X + (($count +1)* .25))] = GUICtrlCreateInput("", $Left, $Top + 170, 100, 20, 0x1000)
    
; row 3
    GUICtrlCreateLabel($Header_2 & " " & $X, $Left, $Top + 220, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .5))] = GUICtrlCreateLabel("", $Left, $Top + 240, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .5))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .5))], "00:00:00")
    $TButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Start", $Left, $Top + 270, 50, 20)
    $SButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 270, 50, 20)
    $Input_[($X + (($count +1)* .5))] = GUICtrlCreateInput("", $Left, $Top + 290, 100, 20, 0x1000)
    
; row 4
  
    If ($X + (($count +1)* .75)) = ($count + 1) Then
        $Icon_1 = GUICtrlCreatePic($Toy_Banner, $Left, $Top + 360, 100, 50)
        GUICtrlSetState(-1, $GUI_DISABLE)
        ExitLoop
    EndIf
    GUICtrlCreateLabel($Header_3 & " " & $X, $Left, $Top + 340, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .75))] = GUICtrlCreateLabel("", $Left, $Top + 360, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .75))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .75))], "00:00:00")
    $TButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Start", $Left, $Top + 390, 50, 20)
    $SButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 390, 50, 20)
    $Input_[($X + (($count +1)* .75))] = GUICtrlCreateInput("", $Left, $Top + 410, 100, 20, 0x1000)
    
    $Left = $Left + 110
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    
    For $xk = 1 To $count
        If $msg = $TButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" Then
            GUICtrlSetState($TButton_[$xk], $GUI_DISABLE)
            GUICtrlSetState($Input_[$xk], $GUI_DISABLE)
            $TimerActive_[$xk] = 1
            $Timer_[$xk] = TimerInit()
        ElseIf $msg = $TButton_[$xk] Then
            MsgBox(64, "User Error:  " & $xk, "Please Type in a User Name   ", 3)
        EndIf
        If $msg = $SButton_[$xk] And GUICtrlRead($SButton_[$xk]) = "Reset" Then
            GUICtrlSetData($Label_[$xk], "00:00:00")
            GUICtrlSetData($Input_[$xk], "")
            GUICtrlSetData($SButton_[$xk], "Stop")
            GUICtrlSetState($TButton_[$xk], $GUI_ENABLE)
            GUICtrlSetState($Input_[$xk], $GUI_ENABLE)
        EndIf
        If $msg = $SButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" And GUICtrlRead($SButton_[$xk]) = "Stop" Then
            $TimerActive_[$xk] = 0
            GUICtrlSetData($SButton_[$xk], "Reset")
            
       ;
            GUICtrlSetColor($Label_[$xk], 0x000000)
            $Name = GUICtrlRead($Input_[$xk])
       ;
            If $xk <= (($count +1)* .5) Then
                $Unit = $Header_1 & "  " & $xk
            EndIf
            If $xk > (($count +1)* .5) And $xk <= (($count +1)* .75) Then
                $Unit = $Header_2 & "   " & ($xk - (($count +1)* .5))
            EndIf
            If $xk > (($count +1)* .75) Then
                $Unit = $Header_3 & "   " & ($xk - (($count +1)* .75))
            EndIf
            RecordStuff()
        EndIf
    Next
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func AllTimers()
    Local $Secs, $Mins, $Hour
    For $ck = 1 To $count
        
        If $TimerActive_[$ck] Then
            _TicksToTime(Int(TimerDiff($Timer_[$ck])), $Hour, $Mins, $Secs)
            $Time_[$ck] = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
            If $sTime_[$ck] <> $Time_[$ck] Then GUICtrlSetData($Label_[$ck], $Time_[$ck])
            If $Mins > 29 Then GUICtrlSetColor($Label_[$ck], 0xff0000)
        EndIf
    Next
EndFunc ;==>AllTimers

Func RecordStuff()
    $LogStuff = FileOpen($Today_File, 1)
    FileWriteLine($LogStuff, "Station: " & $Unit & @CRLF)
    FileWriteLine($LogStuff, "User name: " & (GUICtrlRead($Input_[$xk])) & @CRLF)
    FileWriteLine($LogStuff, "Total time: " & (GUICtrlRead($Label_[$xk])) & @CRLF & @CRLF)
    FileClose($LogStuff)
    
EndFunc ;==>RecordStuff

Func Setup()
$Set_win = GUICreate("   Toy BOX  -  Multi-Station-Timer", 350, 310)
GUISetIcon($Logo_icon)
$Icon_1 = GUICtrlCreatePic($Toy_Logo, 240, 10, 100, 250)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("3 Group Names", 10, 10, 220, 135)
$Head_1 = GUICtrlCreateInput($Header_1, 30, 40, 150, 20)
$Head_2 = GUICtrlCreateInput($Header_2, 30, 75, 150, 20)
$Head_3 = GUICtrlCreateInput($Header_3, 30, 110, 150, 20)
GUICtrlCreateGroup("Number of Timers", 10, 155, 220, 150)
$Note = GUICtrlCreateLabel("19 Total Timers", 30, 175, 150, 20, $SS_SUNKEN + $SS_CENTER  )
$Rad_[1] = GUICtrlCreateRadio("3", 40, 200, 30, 20)
$Rad_[2] = GUICtrlCreateRadio("7", 40, 220, 30, 20)
$Rad_[3] = GUICtrlCreateRadio("11", 40, 240, 30, 20)
$Rad_[4] = GUICtrlCreateRadio("15", 40, 260, 30, 20)
$Rad_[5] = GUICtrlCreateRadio("19", 40, 280, 30, 20)
GUICtrlSetState( -1, $GUI_CHECKED )
$Rad_[6] = GUICtrlCreateRadio("23", 140, 200, 30, 20)
$Rad_[7] = GUICtrlCreateRadio("27", 140, 220, 30, 20)
$Rad_[8] = GUICtrlCreateRadio("31", 140, 240, 30, 20)
$Rad_[9] = GUICtrlCreateRadio("35", 140, 260, 30, 20)
$Rad_[10] = GUICtrlCreateRadio("39", 140, 280, 30, 20)
$Create = GUICtrlCreateButton("Create", 250, 270, 80, 30)

GUISetState()

While 1
    $msg2 = GUIGetMsg()
    If $msg2 = $Create Then
        $Header_1 = GUICtrlRead($Head_1)
        $Header_2 = GUICtrlRead($Head_2)
        $Header_3 = GUICtrlRead($Head_3)
        For $tk = 1 to 10
            If GUICtrlRead($Rad_[$tk]) = $GUI_CHECKED Then
                $pk = $tk
                $Radx = $tk * 2
                $count = (($tk * 4)-1)
                ExitLoop
            EndIf
        Next
        ExitLoop
    EndIf
    For $t = 1 to 10
        If GUICtrlRead($Rad_[$t]) = $GUI_CHECKED Then
                GUICtrlSetData( $Note, (($t * 4)-1) & " Total Timers")
                ExitLoop
        EndIf
    Next    
    If $msg2 = $GUI_EVENT_CLOSE Then ExitLoop
    Sleep(70)
WEnd

GUIDelete($Set_win)
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

What I really wanted was to adlibs executing at different times. ankistr's method didn't really provide even though it was "resourceful" lol.

So in the end I had one adlib and used TimerInit and in the function called by adlib I had it do whatever I wanted every 10ms and did TimerDiff() to check if it was time to do what I wanted to do every 10 seconds. It works... or so I think even though two adlibs would have been much easier.

Well my method works if you are using the adlib function for what it is meant to be used, that is, to check any uncertainities or unexpected behaviour. You obviously didn't mention what you were trying to achieve, so I guess my post wasn't helpful in your case. Using the timer seems to be the right way of doin it i guess.

AdlibEnable("Function1",500)

Func Function1()
;your function code goes here
AdlibDisable()
AdlibEnable("Function2",500)
EndFunc

Func Function2()
;your function code goes here
AdlibDisable()
AdlibEnable("Function1",500)
EndFunc

[topic="80940"] AutoScript Creator, Script to automate anything![/topic]

Share this post


Link to post
Share on other sites

Like I said resourceful and a great idea but not helpful in my case

Share this post


Link to post
Share on other sites

Like I said resourceful and a great idea but not helpful in my case

I'm wondering if it were worth your time to do the search I suggested?

http://www.autoitscript.com/forum/index.ph...ibManager\


[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

SoulA

How to create custom AdlibEnable?

#include <GuiConstantsEx.au3>

Global $TimerProcHandle1 = DllCallbackRegister("_AdlibEnable1", "none", "hwnd;int;int;dword")
Global $TimerProcHandle2 = DllCallbackRegister("_AdlibEnable2", "none", "hwnd;int;int;dword")

Global $TimerCall1
Global $TimerCall2

Global $Left = 0
Global $Right = 250

$hGUI = GUICreate("Test", 300, 200)

$label1 = GUICtrlCreateLabel("String #1", 0, 50, 50, 16)
GUICtrlSetColor(-1, 0xFF0000)

$label2 = GUICtrlCreateLabel("String #2", 250, 100, 50, 16)
GUICtrlSetColor(-1, 0x0000FF)

$StartButton = GUICtrlCreateButton("Start", 10, 160, 75, 23)

$StopButton = GUICtrlCreateButton("Stop", 215, 160, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartButton
            GUICtrlSetState($StartButton, $GUI_DISABLE)
            GUICtrlSetState($StopButton, $GUI_ENABLE)
            _Start()
        Case $StopButton
            GUICtrlSetState($StopButton, $GUI_DISABLE)
            GUICtrlSetState($StartButton, $GUI_ENABLE)
            _Stop()
    EndSwitch
WEnd

Func _Start()
    $TimerCall1 = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, _
                                                          "int", 0, _
                                                          "int", 100, _
                                                          "ptr", DllCallbackGetPtr($TimerProcHandle1))
    
    $TimerCall2 = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, _
                                                          "int", 0, _
                                                          "int", 100, _
                                                          "ptr", DllCallbackGetPtr($TimerProcHandle2))
    $TimerCall1 = $TimerCall1[0]
    $TimerCall2 = $TimerCall2[0]
EndFunc   ;==>_Start

Func _Stop()
    DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $TimerCall1)
    DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $TimerCall2)
EndFunc   ;==>_Stop

Func _AdlibEnable1($hWnd, $Msg, $IdTimer, $dwTime)
    $Left += 5
    If $Left >= 300 Then $Left = 0
    GUICtrlSetPos($label1, $Left, 50)
EndFunc   ;==>_AdlibEnable1

Func _AdlibEnable2($hWnd, $Msg, $IdTimer, $dwTime)
    $Right -= 5
    If $Right <= -50 Then $Right = 250
    GUICtrlSetPos($label2, $Right, 100)
EndFunc   ;==>_AdlibEnable2

Func OnAutoitExit()
    DllCallbackFree($TimerProcHandle1)
    DllCallbackFree($TimerProcHandle2)
EndFunc   ;==>OnAutoitExit

:)

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