[Gambas-user] A Beginner's Guide to Gambas

Rob sourceforge-raindog2 at ...94...
Tue Jul 3 22:01:17 CEST 2007


On Tuesday 03 July 2007, Scott Castaline wrote:
> Your modifications worked. I noticed that you don't have the DIM
> hButton AS Button statement. Is that because of the PUBLIC
> statement in the main routine itself? (PUBLIC hButton AS Button?) 

Yes, it is.  If you have a PUBLIC variable declaration, and then 
declare that same variable with DIM in a subroutine, anything you do 
to that variable is lost when the subroutine finishes.  

In the context of that one form, think of the PUBLIC one as being a 
global variable, whereas any DIM variable is a local variable.  
Anything that needs to last longer than a subroutine should be 
declared with PUBLIC (or PRIVATE, if you don't need to access it in 
other forms or modules) and anything temporary like a loop variable 
should be declared using DIM.  

Other than that, it's up to your discretion, but declaring it both 
ways can cause some confusion as you can see.

In one of Ron Onstenk's replies to your posts, he actually suggested 
commenting out the DIM line for this same reason.  But the replies 
were going back and forth pretty fast, so it wouldn't surprise me if 
you missed that one.

Rob




More information about the User mailing list