Sign in to follow this  
Followers 0
Guest Monkey

Func... And Return

4 posts in this topic

Hello everybody...

This is my first post, so be kind... :D

Global $x
x(1,2)

func x ($a,$b)
$c=$a+$b
If $c=5 then
;c=5
    Return ("1")
    msgbox (0,"","C=5")
Else
;c<>5   
    Return ("0")
    msgbox (0,"","C<>5")
EndIf
EndFunc

I don't really understand the 'Return' issue. Since the msgboxs are not displayed, where the script "goes" once it arrives to the Return command?

Thanks for the help!

Share this post


Link to post
Share on other sites



Return exits the function. The program starts again from the line after where the function has been called.

you can assign the func value to a variable and use it, the variable will have the return value.

E.g.

Global $x
$h = x(1,2)

If $h = 0 Then MsgBox(0,"","the function returned 0")
If $h = 1 Then MsgBox(0,"","the function returned 1")

func x ($a,$b)
$c=$a+$b
If $c=5 then
;c=5
Return ("1")
msgbox (0,"","C=5")
Else
;c<>5 
Return ("0")
msgbox (0,"","C<>5")
EndIf
EndFunc

Share this post


Link to post
Share on other sites

Return basically means: Stop the function here and return to where it was called from ... optionally with a return value...

Global $x
$rc=x(1,2)
if $rc = 1 then 
  ; c = 5
endif

func x ($a,$b)
   $c=$a+$b
   If $c=5 then
     ;c=5
      msgbox (0,"","C=5")
      Return (1) 
   Else
     ;c<>5 
      msgbox (0,"","C<>5")
      Return (0) 
   EndIf
EndFunc

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

Thank you very very much. This was helpfull.

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