Hi,
I haven't actually tried any of this... But, if I recall correctly, variable
scope is the scope at which the variable was first found. If you want a bunch
of dynamic variables to be global, just initialize them at the top of the
formula, before any function declarations.
e.g.
for (i = 0; i < 10; i++) {
VarSet("MyVar" + i, 0);
}
function MyFunc() {
...
}
As for returning a dynamic variable; It really does not matter what you return
from the function. The resulting value will be copied to the caller.
Finally, to dereference a dynamic array, try fetch the array first then
dereference second.
e.g.
MyArray = VarGet("someArray" + n);
Value = MyArray[i];
Mike
--- In [email protected], "necroboy2" <blair.an...@...> wrote:
>
> Hi All,I've been looking through previous messages and the Amibroker
> user guide and have been unable to find an answer, so I hope one of you
> can help.
> When defining a Dynamic Variable is behaves like a normal variable in
> terms of scope. So if defined outside of a function its scope will be
> global, and if defined within a function its scope will be restricted to
> be within that function.
> To make a normal variable that is defined within a function global we
> can use the global keyword. Is there a way we can also do this for
> dynamic variables? I tried global VarSet("someVariable"+i,n); but that
> just throws a syntax error.
> Now I could just not use functions, but that's just bad design. Is there
> a way I can define global dynamic variables from within a function, or
> perhaps return dynamic variables from a function?
> ---------------Now for the second question:
> How do I reference a specific element of an Array that is a Dynamic
> Variable?
> With a normal array I can just do this someArray[1]But with a Dynamic
> Variable that is an array I can't do this VarGet("someArray"+n[1]) or
> this VarGet("someArray"+n)[1]
>
> Cheers, Blair
>