[Gambas-user] Gambas 3 arrays usage
GMail
adamnt42 at ...626...
Sun May 6 14:39:20 CEST 2012
On Sun, 2012-05-06 at 13:06 +0100, RICHARD WALKER wrote:
> Greetings to the list on a fine Sunday afternoon (should be outside
> enjoying it instead of hacking on a new project!).
>
> I am having difficulty understanding the correct way to program with
> arrays in Gambas 3. The documentation has this warning notice:
>
> In Gambas 3, embedded arrays cannot be used as local variables
> anymore. But they can be public!
>
> This is from http://gambasdoc.org/help/lang/arraydecl?show&v3
>
> The same page shows that local variables are declared as:
>
> (1) DIM Identifier AS [ NEW ] Datatype [ Array dimensions ... ]
>
> Embedded arrays are defined as being declared in this way:
>
> (2) [ STATIC ] { PUBLIC | PRIVATE } Identifier [ Array dimensions ...
> ] AS Native Datatype
>
> My difficulty is that I do not understand how an embedded array
> declared with syntax (2) can be taken for a local variable, which is
> declared with syntax (1). Is there some other non-technical meaning
> for "local variable" which is intended in the notice?
>
> Richard
Ah! Richard,
Isn't language a wonderful thing.
Or syntax, if you prefer.
Look very, very carefully at the bits before "Identifier" in that help
page. Now think, where do I use those keywords "DIM" and "PRIVATE" when
declaring a variable (or a constant for that matter).
Got it?
No?
Class Frog
Static Private maxlegs as Integer
Private legs as integer
Public Sub _new(iLegs as Integer)
Dim mylegs as Integer
If iLegs<=Frog.maxlegs then
mylegs=iLegs
legs=mylegs
Endif
End
Static Public Sub _init()
maxlegs=3
End
If the above hasn't got frogs legs, eggs and whatever dancing before
your eyes, go back and look at each of the 37 words.
It may take some practice.... it's taken me about 3 years :-)
Bruce
More information about the User
mailing list