[Gambas-user] Dim keyword in a KeyPress event
Doriano Blengino
doriano.blengino at ...1909...
Mon Aug 11 10:22:07 CEST 2008
richard terry ha scritto:
> I wondered about the use of Dim within a keypress event
>
> e.g:
>
> Public Sub EditArea_KeyPress()
>
> Dim x as integer
>
> BLA BLA DO WHATEVER
>
> End
>
> And whether or not this was bad practice, or if one should use a public
> variable declared at the top of the program.
>
I personally think it is good practice and, on the other hand, Gambas
has nothing wrong with this (i.e., it works well).
Maybe a global variable is faster than a local one, maybe not, but
anyway this has little importance; if from an event handler you use a
global variable, keep in mind that another event handler could come in
place and corrupt your variable. I am not very sure if this can happen
in gambas, but if you use a WAIT instruction, then surely it can happen.
Moreover, it is ugly to declare global variables to be used in localized
scopes, because you loose the logical association between the variable
and the code that uses it. Some languages require you redeclare global
variables if you want to use them in a subroutine; this is added work
for the programmer, but has some advantages.
So, again, use local variables as much as you can.
Cheers,
Doriano Blengino.
More information about the User
mailing list