James Posted September 12, 2007 Share Posted September 12, 2007 Hey all, How can I a make a function in a UDF accept any amount of parameters? Look, I have the following: Func Avg($avg_1, $avg_2, $avg_3, $avg_4, $amount) $add = $avg_1 + $avg_2 + $avg_3 + $avg_4 $final = $add / $amount Return $final EndFunc I need the $avg_# to add as many as possible, and the actual function to calculate it all. -James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
ChrisL Posted September 12, 2007 Share Posted September 12, 2007 Hey all, How can I a make a function in a UDF accept any amount of parameters? Look, I have the following: Func Avg($avg_1, $avg_2, $avg_3, $avg_4, $amount) $add = $avg_1 + $avg_2 + $avg_3 + $avg_4 $final = $add / $amount Return $final EndFunc I need the $avg_# to add as many as possible, and the actual function to calculate it all. -James You wouldn't. I would put all my values in to an array and pass that to a function to work out the averages Local $myArray[11] $myArray[1] = 22 $myArray[2] = 100 $myArray[3] = 9 $myArray[4] = 4 $myArray[5] = 33 $myArray[6] = 12 $myArray[7] = 33 $myArray[8] = 2 $myArray[9] = 200 $myArray[10] = 12 $averages = AVG($myArray) Msgbox(0,"Average",$Averages) Func Avg($aArrayOfValues) Local $vTotal, $final,$amount $amount = Ubound($aArrayOfValues) -1; total number of entries For $i = 1 to $amount $vTotal += $aArrayOfValues[$i] Next $final = $vTotal / $amount Return $final EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 12, 2007 Moderators Share Posted September 12, 2007 You wouldn't. I would put all my values in to an array and pass that to a function to work out the averages Local $myArray[11] $myArray[1] = 22 $myArray[2] = 100 $myArray[3] = 9 $myArray[4] = 4 $myArray[5] = 33 $myArray[6] = 12 $myArray[7] = 33 $myArray[8] = 2 $myArray[9] = 200 $myArray[10] = 12 $averages = AVG($myArray) Msgbox(0,"Average",$Averages) Func Avg($aArrayOfValues) Local $vTotal, $final,$amount $amount = Ubound($aArrayOfValues) -1; total number of entries For $i = 1 to $amount $vTotal += $aArrayOfValues[$i] Next $final = $vTotal / $amount Return $final EndFuncOr you could create the array from a string:Global $myVargs = _MyFunc("abc|def|1|2|##", "|") Func _MyFunc($sArgs, $vDelim = ",") Local $avArray[2] If StringInStr($sArgs, $vDelim) Then $avArray = StringSplit($sArgs, $vDelim) Else $avArray[0] = 1 $avArray[1] = $sArgs EndIf #cs ;Rest of whatever here: ie... For $iCC = 1 TO $avArray[0] ;do whatever NEXT #ce EndFunc 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. Link to comment Share on other sites More sharing options...
James Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks Smoke. Thats just right. And pretty neat and tidy for me too. Thanks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ 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