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. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Gambas-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gambas-user
