PNB Posted September 16, 2017 Share Posted September 16, 2017 Hi, My question is regarding how to pass function as parameter Suppose I have 3 Functions like this Func A() EndFunc Func B($sabc,$pqr,$xyz) EndFunc Func C($abc,$xyz,$test,$text) EndFunc I have to call these function from only function, all function should be call only from one call function.Just pass function name to that function no matter function has multiple paramaters.Without any select,switch case,if, or calling one by one function like this Call("A") Call("B","a","b","c") Call("B","a","b","c","d") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 16, 2017 Moderators Share Posted September 16, 2017 PNB, Welcome to the AutoIt forum. But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "Do not post general support questions here". I have moved it for you, but would ask you to be more careful in future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
LarsJ Posted September 16, 2017 Share Posted September 16, 2017 #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Func A() ConsoleWrite( "A()" & @CRLF ) EndFunc Func B($sabc,$pqr,$xyz) ConsoleWrite( "B(" & $sabc & "," & $pqr & "," & $xyz & ")" & @CRLF ) EndFunc Func C($abc,$xyz,$test,$text) ConsoleWrite( "C(" & $abc & "," & $xyz & "," & $test & "," & $text & ")" & @CRLF ) EndFunc Func CallFunc( $f, $p1 = Default, $p2 = Default, $p3 = Default, $p4 = Default ) Return FuncName($f) = "A" ? $f() : FuncName($f) = "B" ? $f($p1,$p2,$p3) : $f($p1,$p2,$p3,$p4) EndFunc Example() Func Example() CallFunc( A ) CallFunc( B, 1, 2, 3 ) CallFunc( C, 1, 2, 3, 4 ) EndFunc IgImAx 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
jchd Posted September 16, 2017 Share Posted September 16, 2017 3 hours ago, PNB said: I have to call these function from only function, all function should be call only from one call function.Just pass function name to that function no matter function has multiple paramaters. It's the part in bold which keeps you from doing so. Well, unless all parameters are optional (have default values). I see that a "workaround" was just posted but it merely illustrates my point about optional parameters. BTW you rarely need to use Call("A"), just do A() to call it. Also functions are now first-class citizens: a variable can be assigned a function and be passed around. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Gianni Posted September 17, 2017 Share Posted September 17, 2017 As explained in the help of the Call() function you can pass a variable number of arguments to a function using the Call() statement and an 1D array as second argument. That is, you have to stack all your arguments in an 1D array, where the first element (element[0]) must contains the string "CallArgArray" and the following elements contains your arguments (also arrays are allowed as parameters), the receiving function must accept as many arguments as are stacked in the array. So is up to you to prepare the proper array related to the number of arguments accepted by the function you have to call. Call("A") Dim $aArguments[4] = ["CallArgArray", "First parameter", "Second", 3] ; pass 3 arguments Call("B", $aArguments) Dim $aArguments[5] = ["CallArgArray", 1, "Second", 3, 4] ; pass 4 arguments CallMyFunction("C", $aArguments) ; use your custom function to make the Call ; this function call another function and pass as many arguments as contained in the array (if any) Func CallMyFunction($FunctionName, $aArguments = "") Call($FunctionName, $aArguments) EndFunc ;==>CallMyFunction Func A() ConsoleWrite("Function A() has no arguments" & @CRLF) EndFunc ;==>A Func B($sabc, $pqr, $xyz) ConsoleWrite("Received: " & $sabc & @TAB & $pqr & @TAB & $xyz & @CRLF) EndFunc ;==>B Func C($abc, $xyz, $test, $text = "") ConsoleWrite("Received: " & @NumParams & " arguments." & @CRLF) EndFunc ;==>C IgImAx 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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