BlueScreen Posted April 2, 2004 Share Posted April 2, 2004 Global $a Global $b Global $c Action (2,4,7) Msgbox (0,"first number",$a) Msgbox (0,"second number",$b) Msgbox (0,"third number",$c) Func Action ($a, $b, $c) Msgbox (0,"Sum is",$a+$b+$c) Endfunc Why can't I see the values of $a,$b,$c once the function was executed? What can I do to see the values? 10x Link to comment Share on other sites More sharing options...
ezzetabi Posted April 2, 2004 Share Posted April 2, 2004 Global $a Global $b Global $c Action (2,4,7) Msgbox (0,"first number",$a) Msgbox (0,"second number",$b) Msgbox (0,"third number",$c) Func Action (byref $a, byref $b, byref $c) Msgbox (0,"Sum is",$a+$b+$c) Endfunc Why can't I see the values of $a,$b,$c once the function was executed? What can I do to see the values? 10xTry this! Link to comment Share on other sites More sharing options...
ezzetabi Posted April 2, 2004 Share Posted April 2, 2004 Ripped from help file, that everyone should read.. The ByRef keyword is optional and means: (1) the parameter must a variable, and (2) the variable could be changed by the function. By default, a parameter is passed by value which means that a copy of the parameter's value is manipulated by the function. Link to comment Share on other sites More sharing options...
BlueScreen Posted April 2, 2004 Author Share Posted April 2, 2004 Sorry, but it doesn't seem to work. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 2, 2004 Developers Share Posted April 2, 2004 The Byref in this casse will give you an error unless you specify Vars in the statment that calls "Action". Think you are mixing up some logic here. You define global vars but still define them in Action ($a,$b,$c) and i believe they will be LOCAL vars when you define them on the func statement. So this would work: Global $a=2 Global $b=4 Global $c=7 Action () Msgbox (0,"first number",$a) Msgbox (0,"second number",$b) Msgbox (0,"third number",$c) Func Action () Msgbox (0,"Sum is",$a+$b+$c) Endfunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BlueScreen Posted April 2, 2004 Author Share Posted April 2, 2004 10x JdeB, but I must use some parameters in the function: "Action (2,4,5)" Can't do: "Action ()" Is there another way? Link to comment Share on other sites More sharing options...
BlueScreen Posted April 2, 2004 Author Share Posted April 2, 2004 You define global vars but still define them in Action ($a,$b,$c) and i believe they will be LOCAL vars when you define them on the func statement.Right. The 3 globals are not necessary Link to comment Share on other sites More sharing options...
Developers Jos Posted April 2, 2004 Developers Share Posted April 2, 2004 Something like this maybe? ( I am a bit lost as to what you need to accomplish...) Global $a Global $b Global $c Action (2,4,7) Msgbox (0,"first number",$a) Msgbox (0,"second number",$b) Msgbox (0,"third number",$c) Func Action ($a2, $b2, $c2) $a=$a2 $b=$b2 $c=$c2 Msgbox (0,"Sum is",$a+$b+$c) Endfunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BlueScreen Posted April 2, 2004 Author Share Posted April 2, 2004 Gr8. This is good. So I guess there is no other way to use a variable declared by a function <Action (2,6,8)> rather than doing the $...=$... tweak inside the function. But this is good enough. 10x alot. Link to comment Share on other sites More sharing options...
Valik Posted April 2, 2004 Share Posted April 2, 2004 (edited) Action(1, 2, 3) MsgBox(4096, "", $a & @LF & $b & @LF & $c) Func Action($a, $b, $c) Global $a = $a Global $b = $b Global $c = $c EndFunc But I question the entire logic of needing to assign global variables by passing them to a function. Why use a function? Why pass parameters? Edited April 2, 2004 by Valik Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now