Jump to content

AdLibs UDF - simple multiple AdLib Management


ResNullius
 Share

Recommended Posts

Normally for multiple AdLibs I would do the standard procedure of using the designated AdLib function to call multiple other functions, like this:

AdLibEnable("_AdLibs")
;
;script here
;
Func _AdLibs()
  _Adlib1()
  _AdLib2()
  _AdLib3()
;etc
EndFunc

But, I had a need recently to read options from an ini file and dynamically add to or remove AdLibbed functions.

I did a little searching and didn't see any thing that suited my needs so I whipped this up and thought I'd share.

[standard Disclaimer] The following code does not necessarily represent "best practices": there are probably better, faster, more efficient ways of accomplishing the same thing. But it works for me!

There is next to no error checking implemented so if you break it, debug and fix it.

I have not implemented any of the TimerInit()/TimerDiff functions that others are using for multiple AdLibs

(though I'm sure it could be done); this is for simple straightforward stuff.

[/standard Disclaimer]

Special note to noobs:

This is not an excuse to compensate for scripting abilities worse than mine by stacking up

AdLibbed functions a mile high just because you can't reason out a more efficient way to do things.

And remember... the longer AdLibbed functions take to execute (either because of complexity or because you've stuck in a bunch of Sleep()s the slower your overall script will perform 'cause when your AdLibbin' you ain't doin' nothin' else (unless maybe you're usin' them fancy/schmansy Timer functions :) )

;_AdLibs.au3 a simple Multiple AdLib management UDF by ResNullius
;
#include-once
Global $sAdLibList

Func _Adlibs()
    Local $sAdLibFuncs, $aAdLibFuncs, $sFuncName, $iFunc

    If Not $sAdLibList = "" Then
        $sAdLibFuncs = StringReplace($sAdLibList, Chr(01) & Chr(01), Chr(01))
        If StringLeft($sAdLibFuncs, 1) = Chr(01) Then $sAdLibFuncs = StringTrimLeft($sAdLibFuncs, 1)
        If StringRight($sAdLibFuncs, 1) = Chr(01) Then $sAdLibFuncs = StringTrimRight($sAdLibFuncs, 1)

        $aAdLibFuncs = StringSplit($sAdLibFuncs, Chr(01))

        For $iFunc = 1 To $aAdLibFuncs[0]
            $sFuncName = StringStripWS($aAdLibFuncs[$iFunc], 3)
            If $sFuncName <> "" Then
                Call($sFuncName)
            EndIf
        Next

    Else
        ;The AdLib List is Empty
    EndIf

EndFunc   ;==>_Adlibs

Func _AdLibEnable($sFuncName)
    $sFuncName = StringStripWS($sFuncName, 3)
    If Not StringInStr($sAdLibList, Chr(01) & $sFuncName & Chr(01)) Then
        $sAdLibList &= Chr(01) & $sFuncName & Chr(01)
    EndIf
EndFunc   ;==>_AdLibEnable

Func _AdLibDisable($sFuncName)
    $sFuncName = StringStripWS($sFuncName, 3)
    If StringInStr($sAdLibList, Chr(01) & $sFuncName & Chr(01)) Then
        $sAdLibList = StringReplace($sAdLibList, Chr(01) & $sFuncName & Chr(01), "")
    EndIf
EndFunc   ;==>_AdLibDisableoÝ÷ Ùµ,j¿l0Ømë-jwZ­ÖÀt¸ý·îËb¢{ax[§rبÀ.&Ûy×z-«Þ¥ªÚë^®ÊZ²Ç¶az`%¶.a{¬y©¨¨»¥Ç¶­z÷§¶­r¥vèm¦åÉ·¢w°Ømë¬zêºBjY@®+­¬ªºHë-v'gßÛgyçm«l¢+wöÉè¶Ø^­æ®¶­sb6æ6ÇVFRgV÷CµôDÆ'2æS2gV÷C°¤DÆ$Væ&ÆRgV÷CµôFÆ'2gV÷C² £·67&B7GVfbW&P£°¥ôDÆ$Væ&ÆRgV÷Cµö×7FæF&DDÆ$gVæ2gV÷C²£°£¶Ö&R&VBâæfÆRæBfæB÷RæVVBFòFBæ÷FW"DÆ"÷"GvòÂ6ð¥ôDÆ$Væ&ÆRgV÷Cµö×f'7DWG&DÆ"gV÷C²¥ôDÆ$Væ&ÆRgV÷Cµö×6V6öæDWG&DÆ"gV÷C²£°£¶FòÖ÷&R7GVf`£°£´æòÆöævW"æVVBFRf'7BFFVBFÆ"Â6ð¥ôDÆ$F6&ÆRgV÷Cµö×f'7DWG&DÆ"gV÷C²£°£¶WF

_Adlibs.au3

Link to comment
Share on other sites

Hi,

I've been around AutoIt for a long time, and never known or used Adlib; is there an explanation of what it does somewhere?

I think it may be important now there are all these callback functions available and being triggered, but what is the difference?

Best, Randall

[PS you Example script does nothing, so I acn't see the value of it from the example; could you use an example which functions?

Just "Hello World" 1 and 2 or something?

And ex[plain how that has benefits/ differences/ similarities etc compared to "onevent mode" or is taht not relevant? - maybe that would help me.

Is it on Wikipaedia? I'll look]

Link to comment
Share on other sites

  • 8 months later...

Look at Timers Management in the UDF section of 3.2.11.0

Apologies for my recent, probably callous, comment on this UDF ResNullius. (here.)

I thought this was the best place to explain what I didn't like about it although I didn't know where it came from at the time. I admit that anything you can do I can do worse so I haven't got a very high horse to stand on.

Every time that _AdLibs is called it has to extract the function names from a global string. So it would have made more sense to me to have a global array.

And one thing I thought was missing was that all the ablib functions had to be called at the same frequency which made it less versatile. I accept that for what you needed, and for what many others might need, it is quite adequate (unlike some of my posts. :P )

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I admit that anything you can do I can do worse so I haven't got a very high horse to stand on.

Oh contraire martin, I think if anyone should be making that statement it's me! :idea:

Every time that _AdLibs is called it has to extract the function names from a global string. So it would have made more sense to me to have a global array.

And one thing I thought was missing was that all the ablib functions had to be called at the same frequency which made it less versatile.

I agree with you. I think back in Feb. oof 2008 I was not yet a master of the array.

Timers are something I was thinking of adding too, but as I indicated in my first post with my "fancy/schmansy timer functions" remark, that was also something I hadn't wrapped my head around, although now they seem frightfully obvious.

I accept that for what you needed, and for what many others might need, it is quite adequate

I've always been rather "workman-like" in my approach to writing code: hack together a solution that works (or almost) and then go about refining it until it does what I want.

So, yeah, I needed to dynamically enable/disable 3 or 4 different adlibs at the time based on other script conditions and this was the result: "quite adequate" :P

(unlike some of my posts. :( )

Again, I have learned a great deal from most of your posts (the ones I can understand anyway!).

Your contributions to this community should never be downplayed.

Thanks martin!

Edit: Who knows, one day I just might rewrite this udf using everything I've learned since...

Edited by ResNullius
Link to comment
Share on other sites

Please do update the UDF, I am using it for my icafe for the session timer AND monitor attempts to bypass the timer via launching separate browser AND monitor attempts to launch task manager.

Maybe you can say why it needs to be updated or what problem you have?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Edit: Who knows, one day I just might rewrite this udf using everything I've learned since...

I am always eager to learn. I have produced some useful code for our shop using snippets and learning from code in this forum (yours included), and I am hungry for more. There's tons more code I need to put together, some I don't know how to, but I am confident I will find solutions in this forum.

Thank you both for sharing your code.

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