Jfp87
05-12-2015, 01:56 AM
Guys,
The number of variables I have in my project is beginning to mount and I am still not completely satisfied with how I am using them with regards to being local/public. I am running into some problems and I feel my variables are scattered everywhere.
This is my current thinking although I am starting to get a bit confused:
Any variables which are used between modules, I have defined as Public in the module which calls my userform.
Any variables which are used throughout a module have been defined in the general declarations area of that module using Dim (which in this case is identical to Private?).
Any variables which are needed in a procedure only have been defined within that procedure using Dim.
So if I am entering data into an array which has to be available to all modules and procedures for the duration of the running of the userform, I have declared them as "Public" in the module which calls my userform.
So if I am using counters i, j, x, y etc. in multiple modules, should I be declaring them in each procedure? or privately for the module to save re-dimensioning them each time?
My thought was that they should be re-dimensioned each time to ensure they are being destroyed when not needed.
Anyway, my job today will be to go through my code and try to organise all my variables correctly. Any tips / help on the best way to do this would be a great help.
Cheers guys.
The number of variables I have in my project is beginning to mount and I am still not completely satisfied with how I am using them with regards to being local/public. I am running into some problems and I feel my variables are scattered everywhere.
This is my current thinking although I am starting to get a bit confused:
Any variables which are used between modules, I have defined as Public in the module which calls my userform.
Any variables which are used throughout a module have been defined in the general declarations area of that module using Dim (which in this case is identical to Private?).
Any variables which are needed in a procedure only have been defined within that procedure using Dim.
So if I am entering data into an array which has to be available to all modules and procedures for the duration of the running of the userform, I have declared them as "Public" in the module which calls my userform.
So if I am using counters i, j, x, y etc. in multiple modules, should I be declaring them in each procedure? or privately for the module to save re-dimensioning them each time?
My thought was that they should be re-dimensioned each time to ensure they are being destroyed when not needed.
Anyway, my job today will be to go through my code and try to organise all my variables correctly. Any tips / help on the best way to do this would be a great help.
Cheers guys.