Jump to content

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

TY.

Link to comment
Share on other sites

how this...

$x = 5

$a = myFunc($x)

MsgBox(0,"",$a[1] & @cr & $a[2])

Func myFunc($x)

Dim $y[3]

$y[1]=$x*$x

$y[2]=$y[1]*$x

Return $y

EndFunc

Who needs puzzles when we have AutoIt!!

Link to comment
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
Link to comment
Share on other sites

actually, it couldve been..

$x = 5

$a = myFunc($x)

MsgBox(0,"",$a[0] & @cr & $a[1])

Func myFunc($x)

Dim $y[2]

$y[0]=$x*$x

$y[1]=$y[0]*$x

Return $y

EndFunc

Who needs puzzles when we have AutoIt!!

Link to comment
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.

Link to comment
Share on other sites

$x = 5

$a = myFunc($x)

$a1=$a[0]

$a2=$a[1]

MsgBox(0,"",$a1 & @cr & $a2)

Func myFunc($x)

Dim $y[2]

$y[0]=$x*$x

$y[1]=$y[0]*$x

Return $y

EndFunc

Who needs puzzles when we have AutoIt!!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...