Jump to content

Return value from a function


Recommended Posts

Hi all,

Is there a possibility a function can return more than 1 value? If so, how?

I have searched the HELP and couldn't find it...

Thanks, :o

Can you post an example of what you require as it is not very clear from original post.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

  • Moderators

The only way I'm aware of being able to return more than one value, is if that value is in an array.

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.

Link to comment
Share on other sites

The only way I'm aware of being able to return more than one value, is if that value is in an array.

CODE
Msgbox (0,"",x (5,4))

Func x ($y,$z)
    $New_y=$y*2
    $New_z=$z*2
    
    Return $New_y
    Return $New_z
EndFunc

I want it to return both $New_y and $New_z, but cannot do this:

Return $New_y
Return $New_z

Can you apply your suggestion here?

Link to comment
Share on other sites

Msgbox (0,"",x(5,4))

Func x ($y,$z)
    $New_y=$y*2
    $New_z=$z*2
    
    Return $New_y & " - " & $New_z
EndFunc

Will that do what you want?

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

Using an array

$result = x (5, 4)
For $i = 0 To UBound($result) -1
    Msgbox (0,"", $result[$i])
Next

Func x ($y, $z)
    Local $array[2], $New_y, $New_z
    $New_y = $y * 2
    $New_z = $z * 2

    $array[0] = $New_y
    $array[1] = $New_z
    Return $array
EndFunc
Link to comment
Share on other sites

Hi all,

Is there a possibility a function can return more than 1 value? If so, how?

I have searched the HELP and couldn't find it...

Thanks, :o

By definition "Return" statement can return only one value but if you defined a parameter with the byref attribute if you change this parameter inside the function you will get the variable updated in the calling script. :geek:
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...