Sign in to follow this  
Followers 0
capo

Func param help.

4 posts in this topic

Hey, i have a function that takes lots of params, but how do i make the function hold as many params as the user wants to enter?

like instead of:

Func MyFunc($param1,$param2,$param3,$param4,$param5, and so on)

i can do:

Func MyFunc($param1, ...)

that will take as many params.

Share this post


Link to post
Share on other sites



Hey, i have a function that takes lots of params, but how do i make the function hold as many params as the user wants to enter?

like instead of:

Func MyFunc($param1,$param2,$param3,$param4,$param5, and so on)

i can do:

Func MyFunc($param1, ...)

that will take as many params.

$result = MyFunc(1111111,222222,33333,44444,55555,66666 , _
                 777777,88888,99999,1000000,1100000 ,122222 , _
                 133333,144444,15555,166666,177777,1999999 , _
                 200000,2100000,220000000)

MsgBox(0,"result",$result)




Func MyFunc($param1 = 1 , $param2 = 2 , $param3 = 3 , $param4 = 4 , $param5 =5 ,$param6 = 6 , _
            $param7 = 7 , $param8 = 8, $param9 = 9 , $param10 = 10 , $param11 = 11 , _
            $param12 = 12 , $param13 = 13 , $param14 = 14 , $param15 = 15 , $param16 = 16 , _
            $param17 = 17 ,$param18 = 18 , $param19 = 19 , $param20 = 20 , $param21 = 21 , _
            $param22 = 22 , $param23 = 23 , $param24 = 24 , $param25 = 25 , $param26 = 26 , _
            $param27 = 27 , $param28 = 28 , $param29 = 29 , $param30 = 30 , $param31 = 31 , _
            $param32 = 32 , $param33 = 33 , $param34 = 34 , $param35 = 35 , $param36 = 36 , _
            $param37 = 37 , $param38 = 38 ,$param39 = 39 , $param40 = 40)
Dim $result = 0
For $i = 1 to 40 Step 1
    $result += Eval("param" & $i)
Next
Return $result
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$result = MyFunc(1111111,222222,33333,44444,55555,66666 , _
                 777777,88888,99999,1000000,1100000 ,122222 , _
                 133333,144444,15555,166666,177777,1999999 , _
                 200000,2100000,220000000)

MsgBox(0,"result",$result)




Func MyFunc($param1 = 1 , $param2 = 2 , $param3 = 3 , $param4 = 4 , $param5 =5 ,$param6 = 6 , _
            $param7 = 7 , $param8 = 8, $param9 = 9 , $param10 = 10 , $param11 = 11 , _
            $param12 = 12 , $param13 = 13 , $param14 = 14 , $param15 = 15 , $param16 = 16 , _
            $param17 = 17 ,$param18 = 18 , $param19 = 19 , $param20 = 20 , $param21 = 21 , _
            $param22 = 22 , $param23 = 23 , $param24 = 24 , $param25 = 25 , $param26 = 26 , _
            $param27 = 27 , $param28 = 28 , $param29 = 29 , $param30 = 30 , $param31 = 31 , _
            $param32 = 32 , $param33 = 33 , $param34 = 34 , $param35 = 35 , $param36 = 36 , _
            $param37 = 37 , $param38 = 38 ,$param39 = 39 , $param40 = 40)
Dim $result = 0
For $i = 1 to 40 Step 1
    $result += Eval("param" & $i)
Next
Return $result
EndFunc
Here is wolf9228 example re-written giving the same result.

Global $aMyArray[40] = [1111111, 222222, 33333, 44444, 55555, 66666, _
        777777, 88888, 99999, 1000000, 1100000, 122222, _
        133333, 144444, 15555, 166666, 177777, 1999999, _
        200000, 2100000, 220000000]
        
For $x = 0 to UBound($aMyArray)-1
        if $aMyArray[$x] = 0 Then $aMyArray[$x] = $x +1
next            

MsgBox(0, "result", MyFunc($aMyArray))

Func MyFunc($aMyArray)
    Dim $result = 0
    For $i = 0 To UBound($aMyArray) - 1
        $result += $aMyArray[$i]
    Next
    Return $result
EndFunc ;==>MyFunc

An array can be a parameter.

Edited by Malkey

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Pick an "unused" character, make it your delimiter, then use StringSplit

#include <Array.au3>

MyFunc("param1" & "|" & "param2" & "|" & "param3")
Exit

Func MyFunc($parms)
    $parms = StringSplit($parms, "|")
    _ArrayDisplay($parms,"Parm Count and Parms")
EndFunc
Edited by Spiff59

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0