Program freezes

I have a program that generates an array and uses the generated data to accomplishes some calculations. Now when I use a for - next loop beyond 10 iterations, the program freezes. Is possible that all the arrays remain in memory instead of just populating the same array over again?

I have 512 megs of memory.

LVL 13
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.

Is the for loop less that say 20 lines?
Will help if you post its contents so that we have a better idea of the source of your problem, or suggestions on how to improve your code.


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
gonzal13RetiredAuthor Commented:
The program is about 20 pages at this point. Using debug, I can generate an array and populate it, do the calculations without an error. The problem is that beyond 7 iterations of the program thru the for to next loop it freezes. I would like to be able to repeat the same calculations with different data sets up to 1000 times. It seems like each population of the array is saved in memory.

Without seeing your code, it is hard to put a finger on it.
Is the loop 20 pages long?
Can you just extract the relevant code?
Something like

Dim MyArray(500)
For i = 1 to 10
    ProcessMyArray (Show the relevant lines of code that create the problem)
    Other relevant stuff

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

gonzal13RetiredAuthor Commented:
Ok, I eliminated the calculations and just generated the database 100 times without a problem.This gives me a clue that it is the interaction of the calculations with respect to the database that is the problem. I will keep you posted.

BarshamDevelopment Team LeadCommented:
you must use doevents command and condition commands to verfiying your data writed to your DB so u can have no freeze in your loops
gonzal13RetiredAuthor Commented:
I noticed that when it now freezes after 15 loops the CPU usage is 100 percent. Something is not reinitializing.

The program contains at least 15 pages of if statements and calculations which are addressed after generating the database.
try putting a 'doevents' in the loop.
gonzal13RetiredAuthor Commented:
I am new with visual basic even though I tackled a large project for fun. Please give me a sampe of 'doevents'

For i = 0 To 100
Next i

That is all there is to it gonzal13.  That will allow windows to have some cpu while your program is involved in processor intensive tasks.  Seeing some code would definitely help us in determinine where your issues lie.  Try posting some or all of the calculations you are referring to so we can see if their is a logic error somewhere.

gonzal13RetiredAuthor Commented:
Ok ironwill96 I will try your suggestion.

I used CTRL ALT DEL to get to the cpu performance graph. The program populates an array of about 400 items of data, then does about 15 pages of calculations. Now with a maximum of 6 iterations of the program the cpu usage does not reach 100 percent. I closed out the program to insure that there as nothin in memory. When I opened the program and increased the iterations to 7 then the cpu usage went to 100 percent.

I have worked on this program for about 5 months and used the debug routine for every possible combinations so I feel very confident that the logic is correct. It would have to be if it does 6 iterations. Why would it not do 7? Also, If I isolate the program that populates the array, I can easily run 100 cycles.

I will try to simplify the calculations so that I can post it.


> Why would it not do 7
Because at that stage it runs out of memory?

gonzal13RetiredAuthor Commented:
It only uses about 256 megs of memory but 100 percent of the cpu when I  go to 7 iterations. At 6 it spikes to about 70 percent. I monitor this thru the CTRL ALT DEL.

I raised the points.

> It only uses about 256 megs of memory
"only" ? That is already 50% of your total memory!

What is the operating system?  And when you look at the task manager, what exactly does each one of the Memory lines say.
I am not a big expert on memory handling, but I would suspect that your CPU jumps to 100% because it is trying to joggle memory around to avoid a crash of your system.

gonzal13RetiredAuthor Commented:
The program uses about the same megs of ram (256) during its procedures even when it runs at 6 iterations or less. The only distinction is that from 1 to 6 one can see on the cpu usage graph a spike up to about 80% of the CPU capacity. At 7 and above it immediately goes to 100 percent and stays there. At this point it freezes. I have even tried to use it in the *.exe version and I still had the same problem.

I have added 'unload me' at many strategic points, in case it wants to access the form. I do notice that the program at 7 and above shows the form with the botom portion of the same form below the original form. This normally was taken care of using 'unload me'

Also noticed that it woud, for no reason, go to a program that is used to allow vertical and horizontal scrolls.

Now I have noticed also when adding input boxes which fills up a 21 inch screen the form that some times will get confused when additional input boxes are added. Now taking this one step further, how would I show one input form and then have it access another form on command.

Also I noticed when I open up the program in win98 it gives me an 'out of memory' note. XP PRO eliminates this problem. It occurs as I said by just loading the program and not adding to the code or trying to run the program.

In summary I am still stumped  why it works at 6 iterations and less without a problem. I guess I will have to spend time using the debug for each of the 7 itterations. It will take a bit of time due to the 15 pages of calculations and the generation of the database of 400 bits of data to be used for the calculations. In addition, which I have not tried at this point, adding the 200 variables in the form which I have bypassed.

Yes, engineers are wierd at least my wife tells me. I never tackle someting simple since I get bored. Thus my first program, is a large one. It is a great exersize for the brain. It is like playing chess where one needs to be 10 steps ahead and know the possibilities that the opponant will take based on each of the 10 moves.

I used to design and install production lines. Each one was different and only data available was the information that came out of research. Thus I feel comfortable tackling large projects, with minimal known information.

What I will do now is to work on the other parts of the program while we sort out this problem. I have documentated almost every line of code to make the program easy to debug.

Thanks all for your comments. I have been on this website actively for a year even though I joined it several years ago. I am simply amaized at the enthusiasm peope have including me when trying to help someone. For me it gives me a warm fuzzy feeling when I have helped some one.

Thanks again



It is a memory problem

A few notes:

Win98 type of Operating Systems have a major memory handling deficiency that was only taken care of with XP.
Everything you say keeps pointing on it being a memory issue.
Unloading forms does not guarantee reduction of memory used. If you unload a form and that form is still referencing something in memory. (In other words you referenced an object from the form but did not set it back to nothing), then that form stays in memory.
>In summary I am still stumped  why it works at 6 iterations and less without a problem
There is one way whereby you can prove me wrong:
Try changing the amount of memory you have. For example, run two copies of the program side by side. I am sure that you will find that the freezing happens long before you get to the 7th iteration.

gonzal13RetiredAuthor Commented:
Ok, I will open VB twice and change the reiterations to 6.

Will let you know soon what happens.

gonzal13RetiredAuthor Commented:
You were right, I checked all of the subroutines which I made to simplify debugging.
Well one rarely used subroutine I found a continuous loop. Somehow it would not be accessed until I went over 8 iterations. Well I did 1000 iterations and it did not foul up. Thanks for commenting on something I did not think possible since I was so careful in the coding and I made a sample data set that I thought covered all conditions.

thanks again

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.