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

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

##### Share on other sites

wow thank you Rick

TY.

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

##### 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 on other sites

but what happens if i need those two variables, i mean not using array.

y(1) and y(2) are array elements.. or a(1) and a(2)

but i want a1 and a2, two variables here -.- confusing

TY.

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

\$a1=\$a[0]

\$a2=\$a[1]

nice!

TY.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

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