wimhek Posted July 12, 2009 Share Posted July 12, 2009 I looked in the FAQ and Other forums. Found some old (2004) questions. Help and documentation is not clear to me But , Is it possible to pass a variable numbers of params to a function. Link to comment Share on other sites More sharing options...
Qousio Posted July 12, 2009 Share Posted July 12, 2009 (edited) I looked in the FAQ and Other forums. Found some old (2004) questions. Help and documentation is not clear to me But , Is it possible to pass a variable numbers of params to a function. Not sure what you mean.. Possibly something like this: Func Somefunc($Somevariable) MsgBox( 0, "", $Somevariable ) EndFunc Somefunc(5) Edited July 12, 2009 by Qousio Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 (edited) Not sure what you mean.. Possibly something like this: Func Somefunc($Somevariable) MsgBox( 0, "", $Somevariable ) EndFunc Somefunc(5) Nope I want to code this $x= myfunc($a,$b ) or $x= myfunc($a,$b,$c) functiom myfunc( ???) some coding return($result) endfunc Edited July 12, 2009 by wimhek Link to comment Share on other sites More sharing options...
Qousio Posted July 12, 2009 Share Posted July 12, 2009 Nope I want to code this $x= myfunc($a,$b ) or $x= myfunc($a,$b,$c) functiom myfunc( ???) some coding return($result) endfunc Func functioname ( [Const] [byRef] $param1, ..., [Const] [byRef] $paramN, $optionalpar1 = value, ...) ... [Return [value]] EndFunc Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 Func functioname ( [Const] [byRef] $param1, ..., [Const] [byRef] $paramN, $optionalpar1 = value, ...) ... [Return [value]] EndFunc OK this is copied from the help. Problem is that I must know in advance how many params I am going to pass. PS I dont want to use an array as param. PS I dont want to us to pas one param with delimiterd e.g. $a="one|two|three" myfunc($a) Any help much appreciated. Link to comment Share on other sites More sharing options...
Qousio Posted July 12, 2009 Share Posted July 12, 2009 (edited) OK this is copied from the help. Problem is that I must know in advance how many params I am going to pass. PS I dont want to use an array as param. PS I dont want to us to pas one param with delimiterd e.g. $a="one|two|three" myfunc($a) Any help much appreciated. I'm not sure if you quite understand the difference between passing and returning parameters... Heres and example: Func Func1($ B) $a = 5 $o = $B + $a Return $a + $o EndFunc ;==>Func1 Func Func2($c, $d) $g = $c + $d MsgBox(0, "", $g) EndFunc ;==>Func2 While 1 Func2(3, Func1(3)) WEnd Passing a parameter means we transfer the value of a local paramter to a different function... While returning means returning some value from a function, for example $a+$b+$c etc. Although you can pass by returning aswell.... You can just use global parameters by the way. Just declare them outside of a function, or as Global $parameter. Edited July 12, 2009 by Qousio Link to comment Share on other sites More sharing options...
Yashied Posted July 12, 2009 Share Posted July 12, 2009 (edited) @wimhekRead this to start. Edited July 12, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
trancexx Posted July 12, 2009 Share Posted July 12, 2009 ... anyway expandcollapse popup; Case 1 $X = _MyFunc() ConsoleWrite($X & @CRLF) ; Case 2 $X = _MyFunc(7, 12) ConsoleWrite($X & @CRLF) ; Case 3 $X = _MyFunc(1, 2, 3) ConsoleWrite($X & @CRLF) ; Case 4 $X = _MyFunc(1, 2, 3, 965) ConsoleWrite($X & @CRLF) ; Case 5 $X = _MyFunc(112, 2, 3, 355, -472) ConsoleWrite($X & @CRLF) Func _MyFunc($A = 0, $B = 0, $C = 0, $D = 0, $E = 0) Local $iResult = $A + $B + $C + $D + $E Return $iResult EndFunc ;==>_MyFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 I'm not sure if you quite understand the difference between passing and returning parameters... Heres and example: Func Func1($ B) $a = 5 $o = $b+$a Return $a+$o EndFunc Func Func2($c, $d) $g = $c+$d MsgBox(0, "", $d ) EndFunc While 1 Func2(3, Func1(3)) Wend Passing a parameter means we transfer the value of a local paramter to a different function... While returning means returning some value from a function, for example $a+$b+$c etc. Although you can pass by returning aswell.... You can just use global parameters by the way. Just declare them outside of a function, or as Global $parameter. OK let me try to explain. I want to create a function , and I want to pass a variable number of variables to that function. e.g. $rc=Myfunc($a) ... $rc=Myfunc($a,$b,$c) .... $rc=Myfunc($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p) Link to comment Share on other sites More sharing options...
Qousio Posted July 12, 2009 Share Posted July 12, 2009 (edited) OK let me try to explain. I want to create a function , and I want to pass a variable number of variables to that function. e.g. $rc=Myfunc($a) ... $rc=Myfunc($a,$b,$c) .... $rc=Myfunc($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p) I guess you don't quite understand what a variable is... You can't put 10 variables in one, unless you have declared a special type of variable. I am not sure if this is possible in Autoit. You could do, $rc[0]=$a, $rc[1]=$b etc... But $rc=$a,$b,...$n does not make sense. How do you even imagine this? If $a,$b etc. is text and you want to combine it, you could juse use $a & $b & $c & $d etc. If its integers\reals then you would do $rc=$a+$b+$c etc., But $rc=$a,$b does not make sense... Perhaps if you explained what type $a, $b, $c etc. is ? Are they strings? What are you trying to achieve when outputting $rc ? Edited July 12, 2009 by Qousio Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 ... anyway expandcollapse popup; Case 1 $X = _MyFunc() ConsoleWrite($X & @CRLF) ; Case 2 $X = _MyFunc(7, 12) ConsoleWrite($X & @CRLF) ; Case 3 $X = _MyFunc(1, 2, 3) ConsoleWrite($X & @CRLF) ; Case 4 $X = _MyFunc(1, 2, 3, 965) ConsoleWrite($X & @CRLF) ; Case 5 $X = _MyFunc(112, 2, 3, 355, -472) ConsoleWrite($X & @CRLF) Func _MyFunc($A = 0, $B = 0, $C = 0, $D = 0, $E = 0) Local $iResult = $A + $B + $C + $D + $E Return $iResult EndFunc ;==>_MyFunc Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 (edited) OK the test prototype so far : (thanks anyway for yout patience) {{{ $a="ape" $b="nut" $X=tabelregel($a,$b,"another") consolewrite ($X & @CRLF) Func tabelregel($aa[1]="$$",$aa[2]="$$",$aa[3]="$$",$aa[4]="$$",$aa[5]="$$",$aa[6]="$$",$aa[7]="$$",$aa[8]="$$",$aa[9]="$$",$aa[10]="$$",$aa[11]="$$",$aa[12]="$$",$aa[13]="$$") local $x = "<tr>" local $y for $y = 1 to @NumParams $x = $x & "<td>" & $aa[$y] & "</td>" Next return $x & "</tr>" EndFunc }}} Edited July 12, 2009 by wimhek Link to comment Share on other sites More sharing options...
James Posted July 12, 2009 Share Posted July 12, 2009 You want to know how many parameters your function has taken? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 You want to know how many parameters your function has taken?that is the @numparams Link to comment Share on other sites More sharing options...
wimhek Posted July 12, 2009 Author Share Posted July 12, 2009 Found it , eval did the trick {{{ $a="ape" $b="nut" $X=tabelregel($a,$b,"another") consolewrite ($X & @CRLF) Func tabelregel($aa1="$$",$aa2="$$",$aa3="$$",$aa4="$$",$aa5="$$",$aa6="$$",$aa7="$$",$aa8="$$",$aa9="$$",$aa10="$$" ) local $x = "<tr>" local $y for $y = 1 to @NumParams $x = $x & "<td>" & eval("aa" & $y) & "</td>" Next return $x & "</tr>" EndFunc }}} Link to comment Share on other sites More sharing options...
Nutster Posted July 12, 2009 Share Posted July 12, 2009 If understand correctly, you are looking for something like VB's ParamArray. or perl's list passing, where the user can specify a variable number of parameters in the call to a function and then have a mechanism in the definition of the function to read each of those parameters, probably an array. Unfortunately, we have not implemented that behaviour in AutoIt. The most straight-forward way to do something similar would be to pass an array. Func MinVal(Const ByRef $vArray) Local $vMinVal, $iIndex If UBound($vArray, 0) = 0 Then ; Not an array, so just return the value. return $vArray ElseIf UBound($vArray, 0) > 1 Then ; This routine is set up for one-dimensional arrays only. SetError(1, UBound($vArray)) EndIf $vMinVal = $vArray[0] For $iIndex = 1 To UBound($vArray) If $vMinVal > $vArray[$iIndex] Then $vMinVal = $vArray[$iIndex] Next Return $vMinVal EndFunc Global $k[14] $k[0] = 8 $k[1] = 3 . . . $k[13] = 6.279 MsgBox(0, "Testing: Smallest", MinVal($k) ) David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... 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