Jump to content

Recommended Posts

Posted

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

Posted

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!
Posted

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.

  • Developers
Posted

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.
  :)

Posted

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:

  • Developers
Posted

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

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.
  :)

Posted

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

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

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
×
×
  • Create New...