Sign in to follow this  
Followers 0
PerryRaptor

Can AutoIT Dynamically build the Function Name?

16 posts in this topic

Can AutoIT generate the name of a function? I have about a dozen functions that I want to call via one IF...EndIf loop nested inside a While...Wend loop.

CommandArray[x]

If XXXX == CommandArray[$get_x] then

$FunctionName = "Function" & $get_x & "()"

Sleep(1000)

ContinueLoop

EndIf

Func Function1()

.......................

EndFunc

Func Function2()

........................

EndFunc

Share this post


Link to post
Share on other sites



Have you looked at Call()?


[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

Just now I looked at Call() and I don't see how that will work. I had difficulty following the help file instructions and examples.

Share this post


Link to post
Share on other sites

Just now I looked at Call() and I don't see how that will work. I had difficulty following the help file instructions and examples.

That sounds a bit oxymoronic...

Anyways, I don't think Call() can be used to find the function's name, since it requires the function's name to work.


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Easy...I'm from the planet OxyMoronIC

The helpfile didn't make sense as a means to my desire.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Easy...I'm from the planet OxyMoronIC

The helpfile didn't make sense as a means to my desire.

Hence to what I said in my second paragraph/sentence:

Anyways, I don't think Call() can be used to find the function's name, since it requires the function's name to work.

There's probably another command that can be used. I sometimes also despise the help file's "vagueness" :)

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

I'm not sure who's confused; if it's you or me, but you could please explain what you mean with

the word "generate" ? Do you want to run a function, named by mixing strings and variables or

is it something else ?

Maybe something like this...

$i = 2
Call("Function" & $i)

If you're confused by how Call works, then this points out what I said about it earlier today or

yesterday...

Share this post


Link to post
Share on other sites

It is against the doctrine of planet OxyMoronIC to complain about AutoIT because it is free.

Share this post


Link to post
Share on other sites

@Helge...

I read your post regarding Call() too...I'd like to learn more about the command because your post leads me to believe there is more than can be done with it.

I want the IF...EndIF to create the name of the function that matches the one in the CommandArray. After creating the FunctionName, e.g. Function7() execute it.

Share this post


Link to post
Share on other sites

$get_x = 1
While 1
    $FunctionName = "Function" & $get_x & "()"
    Call($FunctionName)
    $get_x = $get_x + 1
    If $get_x = 12
        ExitLoop
    EndIf
WEnd

Would that do it?


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

@Bala...

Doesn't work

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Maybe if you change the "&"s to "+"s

The theory is that it will set "Function1()" for $FunctionName and put that in the Call(). Then it will loop changing it 1 higher, so now "Function2()", and it'll do that until Function12().

Perhaps Call() doesn't work with the "()"

Another option is to just take out the "Call()" part completely and leave it as:

$get_x = 1
While 1
    $FunctionName = "Function" & $get_x & "()"
    $FunctionName
    $get_x = $get_x + 1
    If $get_x = 12
        ExitLoop
    EndIf
WEnd
Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

This works...I didn't need the "()" at the end when generating/creating the function name.

$get_x = "One"
While 1
    $FunctionName = "Function" & $get_x
    Sleep(1000)
    Call($FunctionName)
WEnd

Func FunctionOne()
    MsgBox(0,"Function One", "this is Function #1")
EndFunc

Thanks everyone

Share this post


Link to post
Share on other sites

Hi,

For $i = 0 To 2
    Call("_do" & $i)
Next

Func _do0()
    ConsoleWrite(0 & @CRLF)
EndFunc
Func _do1()
    ConsoleWrite(1 & @CRLF)
EndFunc
Func _do2()
    ConsoleWrite(2 & @CRLF)
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

From:

Anyways, I don't think Call() can be used to find the function's name, since it requires the function's name to work.

To:

Maybe if you change the "&"s to "+"s

The theory is that it will set "Function1()" for $FunctionName and put that in the Call(). Then it will loop changing it 1 higher, so now "Function2()", and it'll do that until Function12().

Perhaps Call() doesn't work with the "()"

Another option is to just take out the "Call()" part completely and leave it as:

$get_x = 1
While 1
    $FunctionName = "Function" & $get_x & "()"
    $FunctionName
    $get_x = $get_x + 1
    If $get_x = 12
        ExitLoop
    EndIf
WEnd
Hmmm... :)

[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

From:

To:

Hmmm... :)

I misunderstood what the question the first time until it was clarified in a later post, it happens. :D


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

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