Out of memory error

Brian.Crawford

Board Regular
Joined
Oct 3, 2007
Messages
136
In many of my subs I turn off one or more of Screenupdating, Calculation (mode) and EnableEvents. To simplify this I have a single sub
.
Public Sub SetAppItems(Optional tSState As Variant, _
Optional tCState As Variant, _
Optional tEState As Variant)

' screen updating enabled ?
If Not IsMissing(tSState) Then Application.ScreenUpdating = tSState
' calculation mode ?
If Not IsMissing(tCState) Then Application.Calculation = tCState
' Events enabled ?
If Not IsMissing(tEState) Then Application.EnableEvents = tEState
End Sub
.
This sets the conditions on entry and exit of appropriate SUBS (such as)
.
SetAppItems(false,xlcalculationmanual,false)
.
If I run the app more than once without restarting EXCEL (ie testing) I get an "Out of Memory" error on the second test. Also in the above call to SetAppitems it seems within the SUB screenupdating does get set to FALSE but on returning back to calling sub it is still TRUE
.
If I use the appropriate "Application....." commands directly within the calling SUB (ie don't use SetAppItems at all) it works fine.
.
Any suggestions
Related, is there a particular order these functions should be called in.
 
OK, first I compiled the App. I got 2 errors on a unused form button that had been deleted & not the code but the Sub involved has never been called (btn_Activate).
I then eliminated all the code in GetInfo except SetAppitems and gradually re-introduced all the code & Calls. No errors at least so far .. but there are occasions where it has been exercised for a while before the error has eventually shown up. Almost like a stack space problem
I'll keep testing.
But... in SetAppItems

' screen updating enabled ?
If Not IsMissing(prevScreen) Then prevScreen = Application.ScreenUpdating
If Not IsMissing(tSState) Then Application.ScreenUpdating = tSState
>>
Where .Screenupdating comes in as True and where tSState is False and after executing the code to the >> point .screenupdating is still True

I though it might be that a variant didn't work here so I set a Dim'd Boolean Var. to tSState and used it instead of tSState, also tried using =False instead of =tSState, I kept .EventsEnabled=True and kept .Calculation =auto...still didn't work. But I can stop before exiting SetAppItems and set it to False ok in the Immediate Window ... go figure
Thoughts (does this happen when you try it?)
Thanks
Brian
 
Last edited:
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
But... in SetAppItems

' screen updating enabled ?
If Not IsMissing(prevScreen) Then prevScreen = Application.ScreenUpdating
If Not IsMissing(tSState) Then Application.ScreenUpdating = tSState
>>
Where .Screenupdating comes in as True and where tSState is False and after executing the code to the >> point .screenupdating is still True

Brian, I see the effect that you are describing, but I believe that is just related to the timing of when the change in property is displayed in the VB Editor. If you add a Watch on the expression Application.ScreenUpdating and check the option to break when the value changes, it breaks at the next statement after the line:
If Not IsMissing(tSState) Then Application.ScreenUpdating = tSState

That internal behavior aside, is the function giving you the result you want?
 
Upvote 0
It's hard to tell as there are only a couple of cells that get changed in that particular SUB. In the other SUBs where I have tried it in the past it seems to be OK. In fact the only reason I discovered it here was when stepping through the code trying to figure out the "Out of Memory" problem.

The O-o-M error is quitely hiding away right now and I won't get back to testing it more for a few days. I will re-post if it reoccurs.
Appreciate all your help on this

Thanks
Brian
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top