StooJ Posted August 3, 2007 Share Posted August 3, 2007 I hope I'm not being too daft and missing something obvious...I'm trying to create a script that will will be added to in the future. I'm trying to design it so that any additions will be as easy as possible with minimum programming. So, I'm creating functions ( using Func...EndFunc ) and hoping to be able to call them by changing a variable (set from a command line parameter eventually, but declared mid-script for now)Can I call a function using a variable? Is there a "treat as literal" capability or something similar? Here's what I've got at the moment:$FuncName = "Test" $FuncName () ; Here's where I'd like to call the function ( in this case Test ) Func Test () Msgbox ( 0 , "Yes" , "It worked!!" ) EndFunc Func NotThisOne () MsgBox ( 0 , "No" , This function shouldn't be called just now" ) EndFuncObviously that won't work, but is there a way for AutoIt to assess the variable and call the correct function? So if $FuncName = "NotThisOne" the second function would be called.Eventually there will be half a dozen functions at least, and I'm hoping to be able to pick between them by altering the command line parameter.Many thanks, I hope I've managed to explain what I'm after. Link to comment Share on other sites More sharing options...
Zedna Posted August 3, 2007 Share Posted August 3, 2007 Call("Test") Func Test () Msgbox ( 0 , "Yes" , "It worked!!" ) EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
qazwsx Posted August 3, 2007 Share Posted August 3, 2007 you could set all of your functions in a switch statement Switch $funcname case "test" Thisfunc () Case "Notthisone" Notthisfunc () Endswitch Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 3, 2007 Share Posted August 3, 2007 I don't think there is a direct function to call Fuctions by name (like there is for variables, Eval). But I do know that some function calls require an input parameter of a second function's name which will get run by the first function, so that sort of functionality IS present (confusing sentence?). Someone else may know how to do that. A work-around: $FuncName = "Test" Switch $FuncName Case "Test" Test() Case "NotThisOne" NotThisOne() EndSwitch Func Test () Msgbox ( 0 , "Yes" , "It worked!!" ) EndFunc Func NotThisOne () MsgBox ( 0 , "No" , "This function shouldn't be called just now" ) EndFunc IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Zedna Posted August 3, 2007 Share Posted August 3, 2007 $FuncName = "Test" Call($FuncName) Func Test () Msgbox ( 0 , "Yes" , "It worked!!" ) EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
StooJ Posted August 3, 2007 Author Share Posted August 3, 2007 (edited) Absolutely perfect, Zedna! Thank you very much. Thanks for the case statement as well, folks, but I want to avoid that as it means I need to add more cases as I go. Edited August 3, 2007 by StooJ Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 3, 2007 Share Posted August 3, 2007 I stand corrected, Call is what I was trying to get across. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Zedna Posted August 4, 2007 Share Posted August 4, 2007 Absolutely perfect, Zedna!Thank you very much.Thanks belongs to Autoit developers because Autoit is so "easy to learn" but strong language. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now