Sign in to follow this  
Followers 0
BlueScreen

Return value from a function

9 posts in this topic

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

Share this post


Link to post
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

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


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


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


[center]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.[/center]

Share this post


Link to post
Share on other sites

Sure.

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

Share this post


Link to post
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?

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks, MHz, that did it... :o

Share this post


Link to post
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:

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