Jump to content
Sign in to follow this  
taylansan

multi output functions - two or more

Recommended Posts

ok here is a simple code and plz tell me how i can get 2 output function

$x = 5

;the problem is here i think?
$a = myFunc($x)
;$a1 = ????
;$a2 = ????

MsgBox(0,"",$a)

Func myFunc($x)
    $y1=$x*$x
    $y2=$y1*$x
    ;is here correct?
    Return $y1 & $y2
EndFunc

now i need $a1 = 25 and $a2 = 125. but miss or my lack of knowladge, i cant handle, i get $a = 25125. because i didnt ..emm seperate them? ...

how can i get those values, withousing global or etc, i mean is there a way to write

($a1, $a2) = myFunc($x)

[$a1, $a2] = myFunc($x) well tried but didnt work :)

Share this post


Link to post
Share on other sites

Don't know if it'll work or help, maybe you could try ..

$x = 5

;the problem is here i think?
$a = myFunc($x)
$spa = StringSplit($a, "|") 

MsgBox(0,"","$y1 = " & $spa[1] & @LF & "$y2 = " & $spa[2])

Func myFunc($x)
    $y1=$x*$x
    $y2=$y1*$x
    ;is here correct?
    Return $y1 & "|" & $y2
EndFunc

Cheers

Edit: I was to slow ..lol

I like Rick's way better :)

Edited by smashly

Share this post


Link to post
Share on other sites

Rick's method shows you how to pass multiple paramaters via an array , each array element stores one value, and you track which one by the

dimension in which the element is stored. This is useful, especially when you name your dimensions using Enum().

Of course, you could also just strip out the references to $y2, call the function twice, and store the result each time.

To pass as a string, you could add a delimiter between your elements , and then parse the result.

You can also use @error and/or @extended to pass numeric information.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

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  

×
×
  • Create New...