Sign in to follow this  
Followers 0
BlueScreen

Simple func not working any more

4 posts in this topic

#1 ·  Posted (edited)

Just wanted to know what the "ByRef" optional parameter means (when using Functions).

10x

Edited by BlueScreen

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

byref means that the value is returned to the variable in the calling code eg:

$a=5
test($a)
msgbox(0,"test", "$a=" & $a); $a will still be 5

Func test($a)
   $a = $a * 10
EndFunc
$a=5
test($a)
msgbox(0,"test", "$a=" & $a); $a will be the retruned result thus 50

Func test(byref $a)
   $a = $a * 10
EndFunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

10x alot! JdeB

Share this post


Link to post
Share on other sites

If you don't want to change the value of $a you can use the return option

$a=5
$b=test($a)
msgbox(0,"$a=" & $a, "$b=" & $b); $a stays 5, $b will be the returned result thus 50

Func test($a)
  $a = $a * 10
Return $a
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

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