## Recommended Posts

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
Return \$final
EndFunc```

I need the \$avg_# to add as many as possible, and the actual function to calculate it all.

-James

##### Share on other sites

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
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

\$myArray = 22
\$myArray = 100
\$myArray = 9
\$myArray = 4
\$myArray = 33
\$myArray = 12
\$myArray = 33
\$myArray = 2
\$myArray = 200
\$myArray = 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```

##### Share on other sites

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

\$myArray = 22
\$myArray = 100
\$myArray = 9
\$myArray = 4
\$myArray = 33
\$myArray = 12
\$myArray = 33
\$myArray = 2
\$myArray = 200
\$myArray = 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```
Or you could create the array from a string:
```Global \$myVargs = _MyFunc("abc|def|1|2|##", "|")
Func _MyFunc(\$sArgs, \$vDelim = ",")
Local \$avArray
If StringInStr(\$sArgs, \$vDelim) Then
\$avArray = StringSplit(\$sArgs, \$vDelim)
Else
\$avArray = 1
\$avArray = \$sArgs
EndIf
#cs
;Rest of whatever here: ie...
For \$iCC = 1 TO \$avArray
;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.

##### Share on other sites

Thanks Smoke. Thats just right. And pretty neat and tidy for me too. Thanks ## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...