Jump to content

Function pointers


Recommended Posts

AutoIT doesn't do pointers, exactly, but you can do this with Execute():

For $n = 1 To 3
    MsgBox(64, "Results", $n & " doubled is " & Execute("_DoubleIt(" & $n & ")"), 2)
Next

Func _DoubleIt($i)
    Return $i * 2
EndFunc   ;==>_DoubleIt

:shocked:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

AutoIT doesn't do pointers, exactly, but you can do this with Execute():

For $n = 1 To 3
    MsgBox(64, "Results", $n & " doubled is " & Execute("_DoubleIt(" & $n & ")"), 2)
Next

Func _DoubleIt($i)
    Return $i * 2
EndFunc   ;==>_DoubleIt

:shocked:

Thanks, at first I thought it wasn't working then I checked return value and saw that it did. However the MsgBoxs within the called functions did not show. Now I need a option like Tcl has to promote the called function to run at the current scope level. Don't suppose eval would work either...

Thanks for the try.

Link to comment
Share on other sites

Huh! :shocked:

Sure enough, this change doesn't present the Msgbox from the function:

For $n = 1 To 3
    MsgBox(64, "Results", $n & " doubled is " & Execute("_DoubleIt(" & $n & ")"), 2)
Next

Func _DoubleIt($i)
    MsgBox(64, "_DoubleIt", "Input to function: " & $i)
    Return $i * 2
EndFunc   ;==>_DoubleIt

Found a reference in the help file under Execute to explain why:

Remarks

Environment, Files, Dir, Disk, GUI, InputBox, MsgBox, Misc, Network, Obj/COM, Process, Registry, Tray, WinKill functions implying deletion or modification will not be executed. They will set @error to 9999 and return "".

Well, AutoIT is a scripting language, not a compiled language. You can't expect full C++ functionality from a less-than-100KB interpreter.

Daddy always said "Learn something new every day."

I just did.

I'm done for the day...

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I have a series of parameterless tasks and thought it would be handy if I could put the names of the ones I wanted to Execute in an array, then just check the return value. But it will be simple enough to add a few lines for each one I want to run.

We tried.

jh

Link to comment
Share on other sites

I have a series of parameterless tasks and thought it would be handy if I could put the names of the ones I wanted to Execute in an array, then just check the return value. But it will be simple enough to add a few lines for each one I want to run.

We tried.

jh

Ooh... that sounded interesting! Like:

#include <array.au3>
$avResults = _ManyFuncs()

Func _ManyFuncs()
    Local $avReturn[1] = [0]
    _ArrayAdd($avResults, _MyFunc1())
    _ArrayAdd($avResults, _MyFunc2())
    ; ...
    _ArrayAdd($avResults, _MyFuncn())
    $avResults[0] = UBound($avResults) - 1
    Return $avReturn
EndFunc

:shocked:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Yes, or if Execute would have supported it , just fill an array with the name strings and in the param list of Execute, & the '()'.

But beggars like me can't be choosy, and I am appreciating the firepower at hand. Gotta prod the boss for a donation when I get this all together.

jh

Link to comment
Share on other sites

Forgive the late reply but Yes, absolutely, that is it!

I check the server for what is installed and gen a list for the user. Now I can use a group of checkboxes for services needed and stuff the list in an array.

Boy howdy, we're coming up with more ways for me to get over my head in trouble every day.

Thanks PsaltyDS!

Best Regards,

jh

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