Sign in to follow this  
Followers 0
BlueScreen

Global And Function Issues

10 posts in this topic

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

Share this post


Link to post
Share on other sites



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?

10x

Try this!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Sorry, but it doesn't seem to work. :whistle:

Share this post


Link to post
Share on other sites

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

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 JdeB, but I must use some parameters in the function: "Action (2,4,5)"

Can't do: "Action ()"

Is there another way?

Share this post


Link to post
Share on other sites

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 :whistle:

Share this post


Link to post
Share on other sites

Something like this maybe? ( :whistle: 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

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

:whistle:

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by Valik

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