Question about DIM statements

If I have a DIM statement inside a timer or a frequently used subroutine, does that re-DIM the variable each time? And does that make my app use up resources that it shouldn't? That's my problem. My app runs a while and the machines run out of resources.
What other things can I adjust or fix to help minimize this problem.?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can Dim within any function, it does not take up more memory every time the function is entered.

There are lots of things which may be causing a memory leak.  What are you doing in the timer?  Are there any other repetitive tasks which may be causing the problem?
If you are dimming any OBJECTS you have to make sure you release them at the close of the procedure, or in your case maybe when you stop using them.  This is a common mistake that some developers make.  For example if oWord were your object:

Dim oWord as Word.Application
Set oWord = New Word.Application  

' do so other stuff
' then exit:

Set oWord = Nothing

In this example if you don't quit word and set it equal to nothing then you will create a new instance of word every time you go through the procedure.  If you were to check the Windows task manager you would see mutiple instances of word running as separate applications.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I'm not trying to answer this question, because both Erick37 & Jon Raymond have already done so, but I thought rbend could use a bit more of an explanation.

A procedure-level variable declared with the DIM statement retains its value until the procedure is finished running. If the procedure calls other procedures, the variable retains its value while those procedures are running as well.

If a procedure-level variable is declared with the STATIC keyword, the variable retains its value as long as code is running in any module. When all code has finished running, the variable loses scope and its value. Its lifetime is the same as a module-level variable.

A module-level variable differs from a static variable. In a standard module or a class module, it retains its value until you stop running your code. In a class module, it retains its value as long as an instance of the class exists. Module-level variables consume memory until you reset their values.

Variables dimensioned as object pointers are supposed to release memory in the same way, however, that is not always the case. Memory leakage can occur, so as Jon recommends, set the object variable to NOTHING as you exit your procedure.
By the way, If your timer event procedure takes longer than the timer period, you'll be nesting event calls. That'll earn you a stack overflow. Try commenting out your timer procedure & see if that fixes the resource problem. If it does, you know what to do.
rbendAuthor Commented:
thanks all of your for your time !
Happy Holidays
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.