Jump to content

Global And Function Issues


Recommended Posts

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

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!
Link to comment
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.

Link to comment
Share on other sites

  • Developers

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

  • Developers

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...