Multiple DIMs for the same variable does not create local variables

jima

Member
Licensed User
Longtime User
It appears that if I DIM a variable in the globals section, then I cannot create local variables of the same name and have them actually created as local variables. It would be nice if the compiler balked when encountering these additional DIMs.

I'd like commentary on this phenomenon.

I originally tested numerous modules separately and discovered this situation when I integrated them into one program. By the way, what are the pros/cons of creating code modules?
 

Ricky D

Well-Known Member
Licensed User
Longtime User
for me the pros are I can put useful related code into a specific module.

I have a Utils module simply named u that holds various constants, variables, database types and subs.

Makes it much easier to add new functionality.

From my perspective I don't have any cons.

Recently I created an updaterecord in dbutils and called it UpdateRecord2
it's in my copy of dbutils.

Down the track I can see it there.

regards, Ricky
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
I don't think this is an error. Once a variable is global it is known to all code. You can re-dim these globals at any point and in any sub, so the compiler has no reason to complain. So if you started with an array of 5,000 and later wanted to release memory, you could now re-dim to 100 elements and the OS would clear the resources.
 
Last edited:
Upvote 0
Top