Jump to content

adlibregister issue


Queener
 Share

Go to solution Solved by SmOke_N,

Recommended Posts

I notice that my button no longer works if I use adlibregister. Is there an alternative way to use button to call function while adlibregister continue to run in the background?

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators

If you comment out line 38 it should solve the issue.

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.

Link to comment
Share on other sites

GUIConstantsEx.au3 line 38? Tried that; didn't work unless you can specific exactly what the line stated...

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Adlib works great, but the button to test the test function doesn't work.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>

HotKeySet("{ESC}", "_Exit")

$TO = GUICreate("TO",495,378,-1,-1,-1,-1)
$bstart = GUICtrlCreateButton("Start",40,330,100,30,-1,-1)

$bstop = GUICtrlCreateButton("Stop",160,330,100,30,-1,-1)
GUICtrlCreateLabel("Current Report:",40,40,126,30,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,"-2")
GUISetState(@SW_SHOW,$TO)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bstart
            Test()
        Case $bstop
            ExitLoop

    EndSwitch
    sleep(1)
    Adlib()
WEnd

Func Adlib()
sleep(10000)
msgbox(0, "", "Test", 5000)
EndFunc

Func Test()
msgbox(0, "Test", "Worked", 10000)
exit
EndFunc

Func _Exit()
    Exit
EndFunc


 
Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators
  • Solution

As czardas tried to imply.

 

As dumbfounded as you were when I said "line 38" and "3rd from the top"... Did you never stop to ask yourself... "How does he know that"?

I don't know that, how could I?  I have no idea what your issue truly is without seeing what code you're actually using and how you're using it.

See... now you post your code and I can tell you....  It was line 32 that was actually your problem... Sleep stops your script for however many milliseconds are set between the parenthesis!

Hey, but I was only 6 lines off for real!

Edit:

Here, no hard feelings. :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

HotKeySet("{ESC}", "_Exit")

$TO = GUICreate("TO", 495, 378, -1, -1, -1, -1)
$bstart = GUICtrlCreateButton("Start", 40, 330, 100, 30, -1, -1)

$bstop = GUICtrlCreateButton("Stop", 160, 330, 100, 30, -1, -1)
GUICtrlCreateLabel("Current Report:", 40, 40, 126, 30, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "-2")
GUISetState(@SW_SHOW, $TO)

AdlibRegister("Adlib", 10000)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bstart
            Test()
        Case $bstop
            ExitLoop

    EndSwitch
WEnd

Func Adlib()
    MsgBox(0, "", "Test", 5000) ; msgbox will stop your script too!
EndFunc   ;==>Adlib

Func Test()
    MsgBox(0, "Test", "Worked", 10000)
    Exit
EndFunc   ;==>Test

Func _Exit()
    Exit
EndFunc

BTW, that code was a mess, and missing a function, and still has script stopping objects.

Edited by SmOke_N

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.

Link to comment
Share on other sites

ahh, ur right... didn't think the sleep would affects it. Was wondering that for a whole week now of testing adlib.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

It's a bit confusing, but this might be what you intend.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>

HotKeySet("{ESC}", "_Exit")

Global $TO = GUICreate("TO",495,378,-1,-1,-1,-1)
Global $bstart = GUICtrlCreateButton("Start",40,330,100,30,-1,-1)

Global $bstop = GUICtrlCreateButton("Stop",160,330,100,30,-1,-1)
GUICtrlCreateLabel("Current Report:",40,40,126,30,-1,-1)
GUICtrlSetFont(-1,12,400,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,"-2")
GUISetState(@SW_SHOW,$TO)

AdlibRegister("Adlib", 10000) ; Call a function every 10 seconds.

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bstart
            Test()
        Case $bstop
            ExitLoop

    EndSwitch
    ; sleep(20) ; A sleep value of 1 is too small, but SmOkE_N is right - this should have been removed.
WEnd

Func Adlib()
    msgbox(0, "Test", "Adlib is working", 5000)
EndFunc

Func Test()
    msgbox(0, "Test", "Worked", 10000)
    exit
EndFunc

Func _Exit()
    Exit
EndFunc

Edit: oops I missed a bit of code.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

A little slow on the draw there czardas :whistle: ... and you're missing an EndFunc :)

Edit:

And sleep is unnecessary with GUIGetMsg(), it has an auto sleep of 250ms ;).

Edited by SmOke_N

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.

Link to comment
Share on other sites

well, putting adlib outside of while; doesn't it only run once and thats it? I was hoping it would continually run while the button is being press.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators

well, putting adlib outside of while; doesn't it only run once and thats it? I was hoping it would continually run while the button is being press.

 

:( ... you obviously didn't run it?  That's the neat thing about SciTe, run the code, wait 10 seconds, get a popup, wait 10 more... what do you get?  Then... (and only then) should you ask your question :) .

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.

Link to comment
Share on other sites

  • Moderators

@czardas, just giving you a hard time lol

@asiaqueen... there's a flaw in the logic of mine... adlib doesn't stop counting milliseconds once it enters the function... and even this scenario is not working like I'd expect:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

Global $giAdlibMills = 10000
HotKeySet("{ESC}", "_Exit")

$TO = GUICreate("TO", 495, 378, -1, -1, -1, -1)
$bstart = GUICtrlCreateButton("Start", 40, 330, 100, 30, -1, -1)

$bstop = GUICtrlCreateButton("Stop", 160, 330, 100, 30, -1, -1)
GUICtrlCreateLabel("Current Report:", 40, 40, 126, 30, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "-2")
GUISetState(@SW_SHOW, $TO)

AdlibRegister("Adlib", $giAdlibMills)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bstart
            Test()
        Case $bstop
            ExitLoop

    EndSwitch
WEnd

Func Adlib()
    AdlibUnRegister("Adlib")
    MsgBox(0, "", "Test", 5000) ; msgbox will stop your script too!
    AdlibRegister("Adlib", $giAdlibMills)
EndFunc   ;==>Adlib

Func Test()
    MsgBox(0, "Test", "Worked", 10000)
    Exit
EndFunc   ;==>Test

Func _Exit()
    Exit
EndFunc

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.

Link to comment
Share on other sites

  • Moderators

Damn code tags stopping me from adding to my post and I forgot to add my decimal to hold my edit spot!!!!

But this should work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

Global $giAdlibMills = 10000
Global $giTimerMills = 0

HotKeySet("{ESC}", "_Exit")

$TO = GUICreate("TO", 495, 378, -1, -1, -1, -1)
$bstart = GUICtrlCreateButton("Start", 40, 330, 100, 30, -1, -1)

$bstop = GUICtrlCreateButton("Stop", 160, 330, 100, 30, -1, -1)
GUICtrlCreateLabel("Current Report:", 40, 40, 126, 30, -1, -1)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "-2")
GUISetState(@SW_SHOW, $TO)

$giTimerMills = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bstart
            Test()
        Case $bstop
            ExitLoop
    EndSwitch
    If TimerDiff($giTimerMills) >= $giAdlibMills Then
        Adlib() ; gui funcs will not work now, but they wouldn't with the msgbox either
        $giTimerMills = TimerInit() ; start all over
    EndIf
WEnd

Func Adlib()
    MsgBox(0, "", "Test", 5) ; msgbox will stop your script too!
EndFunc   ;==>Adlib

Func Test()
    MsgBox(0, "Test", "Worked", 10000)
    Exit
EndFunc   ;==>Test

Func _Exit()
    Exit
EndFunc

.

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.

Link to comment
Share on other sites

  • Moderators

czardas, you be the hero and report to bugtrack if it's not already reported.

I'm fairly certain that the global variable that holds timer isn't reset to zero and re-initiated on the new AdlibRegister... I shouldn't say "certain", I should say, that's exactly how it's acting, no idea what the internal code does.

IMO, AdlibUnregister should:

Remove function from adlib

Remove timer <- it doesn't do this

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.

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...