Out of Stack Space

C

Craig Coope

Hi,

I'm getting an "Out of Stack Space" error when using my forms. It does
not happen all the time (had the program running all day and it
happened once)...

I got it on a form.show...

Basically I have about 5 forms and only one will be shown at anyone
time onscreen so I do form1.hide form2.show etc so only one is on at a
time....Is this something that would cause memory to be used up?

I'm not an expert at VB...this is the first thing I have written...

any ideas?

Cheers...

Craig....
 
H

Harlan Grove

Craig Coope said:
I got it on a form.show...

Basically I have about 5 forms and only one will be shown at anyone
time onscreen so I do form1.hide form2.show etc so only one is on at a
time....Is this something that would cause memory to be used up?
....

Yes, depending on what's in your forms. Do they contain a lot of controls or
bitmap/picture images?
 
C

Craig Coope

...

Yes, depending on what's in your forms. Do they contain a lot of controls or
bitmap/picture images?

Not reall....the one the has most items contains 2 comboboxes, a label
a text box, 5 optionbuttons and 2 command buttons....No pictures or
anything else...
 
C

Craig Coope

Not reall....the one the has most items contains 2 comboboxes, a label
a text box, 5 optionbuttons and 2 command buttons....No pictures or
anything else...

Excuse the typos in my last post!
 
C

Craig Coope

Hi,

I'm getting an "Out of Stack Space" error when using my forms. It does
not happen all the time (had the program running all day and it
happened once)...

I got it on a form.show...

Basically I have about 5 forms and only one will be shown at anyone
time onscreen so I do form1.hide form2.show etc so only one is on at a
time....Is this something that would cause memory to be used up?

I'm not an expert at VB...this is the first thing I have written...

any ideas?

Cheers...

Craig....

Sorry for the repeat posts but I have been looking at my Call Stack
and it says

VBAProject.form1.commandbutton1_click
<Non-Basic Code>
VBAProject.form2.commandbutton1_click
<Non-Basic Code>
VBAProject.form3.commandbutton1_click
<Non-Basic Code>
VBAProject.form4.commandbutton1_click
<Non-Basic Code>
VBAProject.form1.commandbutton1_click
<Non-Basic Code>
VBAProject.form2.commandbutton1_click
<Non-Basic Code>
VBAProject.form3.commandbutton1_click
<Non-Basic Code>
VBAProject.form4.commandbutton1_click

As you can see it is repeating after form4...is it supposed to get
every one in the stack like this?
 
H

Harlan Grove

Craig Coope said:
Sorry for the repeat posts but I have been looking at my Call Stack
and it says

VBAProject.form1.commandbutton1_click
<Non-Basic Code>
VBAProject.form2.commandbutton1_click
<Non-Basic Code>
VBAProject.form3.commandbutton1_click
<Non-Basic Code>
VBAProject.form4.commandbutton1_click
<Non-Basic Code>
VBAProject.form1.commandbutton1_click
<Non-Basic Code>
VBAProject.form2.commandbutton1_click
<Non-Basic Code>
VBAProject.form3.commandbutton1_click
<Non-Basic Code>
VBAProject.form4.commandbutton1_click

As you can see it is repeating after form4...is it supposed to get
every one in the stack like this?

Are your forms calling/displaying each other?
 
C

Craig Coope

Are your forms calling/displaying each other?

Yes...at the end of the code in each form it goes

me.hide
nextform.show

I did this as I only want one form shown on screen at a time...
 
H

Harlan Grove

Craig Coope said:
Yes...at the end of the code in each form it goes

me.hide
nextform.show

I did this as I only want one form shown on screen at a time...

I think this causes problems because you're not returning to the macro that
called the first of these dialogs, but are cycling from one to the next,
eating up stack memory each time.
 
C

Craig Coope

Harlan Grove said:
I think this causes problems because you're not returning to the macro that
called the first of these dialogs, but are cycling from one to the next,
eating up stack memory each time.

I think so too but now I don't know what to do..I have just changed my code
and taken out all of the hide and shows at the end of the code for each form
(so the forms aren't technically calling eachother) and placed it all in one
module like this

Sub hide1()
Pickers.hide
Runinfo1.Show
End Sub

Sub hide2()
Runinfo1.hide
Pickers.Show
End Sub

Sub hide3()
Pickers.hide
Endrun1.Show
End Sub

Sub hide4()
Endrun1.hide
timelost.Show
End Sub

Sub hide5()
timelost.hide
Pickers.Show
End Sub

Then all I have done is refer to the required sub hide at the end of each
form. However it is still keeping everything in the call stack. I understand
what you mean by return to the first macro that called the first form but
I'm not sure how to implement that in code.
 
C

Craig Coope

Sorry for the repost....

OK I think (hope!) this will help me...

If you had 3 forms...

form1
form2
form3

and on each form you had one commandbutton and all the command button
did was open the next form (and hide the current) what code would you
have and where?

If someone tells me the code for something as simple as this I think
I'll be able to fit it around my stuff...

I would have

form1
sub commandbutton1_click
form1.hide
form2.show
end sub

form2
sub commandbutton1_click
form2.hide
form3.show
ebd sub

form3
sub commandbutton1_click
form3.hide
form1.show
end sub

The abaove is very simple but as I said it causes the call stack to
keep expanding...

So how would you do it?

Many many thanks
 
K

kounoike

this is a sample only to show form1, form2, form3 in this sequence three
times.

in standard module
Sub showform()
Dim i As Long
Do While (i < 3)
UserForm1.Show
UserForm2.Show
UserForm3.Show
i = i + 1
Loop
End Sub

in UserForm1 module
sub commandbutton1_click
UseForm1.hide ' Or Me.Hide

end sub

in UserForm2 module
sub commandbutton1_click
UserForm2.hide ' Or Me.Hide
end sub

in UseFform3 module
sub commandbutton1_click
UserForm3.hide ' Or Me.Hide
end sub

keizi
 
C

Craig Coope

this is a sample only to show form1, form2, form3 in this sequence three
times.

in standard module
Sub showform()
Dim i As Long
Do While (i < 3)
UserForm1.Show
UserForm2.Show
UserForm3.Show
i = i + 1
Loop
End Sub

in UserForm1 module
sub commandbutton1_click
UseForm1.hide ' Or Me.Hide

end sub

in UserForm2 module
sub commandbutton1_click
UserForm2.hide ' Or Me.Hide
end sub

in UseFform3 module
sub commandbutton1_click
UserForm3.hide ' Or Me.Hide
end sub

keizi

Thanks for the reply....

It sounds simple enough but my problem is that I can't have the forms
in a loop because I have "back" buttons etc incase the user selects
the wrong form in the first place and also it doesn't always go from
form1 to form2 it sometimes goes from form1 to form3 :eek:(...
 
K

kounoike

I know my sample is useless. but if you don't want to eat up stack, you have
to exit a sub first, and then have to call another sub. i think your code is
something like this and this will eat up your stack.

Sub func1()
func2
End Sub

Sub func2()
func3
End Sub

Sub func3()
func1
End Sub

Though this is a one way, but with a public variable in standard module and
by manipulateing it from userform, I think you could control the sequences
of your forms coming up. this may be another useless sample. CommandButton2
is a "back" button, though it could back only one step.
run showform, though this is endless sub.

in standard module
Type fstate
nstate As Long
pstate As Long
End Type

Public fs As fstate

Sub showform()
fs.nstate = 1
fs.pstate = 1
Do
If fs.nstate = 1 Then
UserForm1.Show
ElseIf fs.nstate = 2 Then
UserForm2.Show
ElseIf fs.nstate = 3 Then
UserForm3.Show
Else
Exit Do
End If
Loop
End Sub

in UserForm1 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 2
fs.pstate = 1
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

in UserForm2 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 3
fs.pstate = 2
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

in UseFform3 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 1
fs.pstate = 3
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

keizi
 
C

Craig Coope

I know my sample is useless. but if you don't want to eat up stack, you have
to exit a sub first, and then have to call another sub. i think your code is
something like this and this will eat up your stack.

Sub func1()
func2
End Sub

Sub func2()
func3
End Sub

Sub func3()
func1
End Sub

Though this is a one way, but with a public variable in standard module and
by manipulateing it from userform, I think you could control the sequences
of your forms coming up. this may be another useless sample. CommandButton2
is a "back" button, though it could back only one step.
run showform, though this is endless sub.

in standard module
Type fstate
nstate As Long
pstate As Long
End Type

Public fs As fstate

Sub showform()
fs.nstate = 1
fs.pstate = 1
Do
If fs.nstate = 1 Then
UserForm1.Show
ElseIf fs.nstate = 2 Then
UserForm2.Show
ElseIf fs.nstate = 3 Then
UserForm3.Show
Else
Exit Do
End If
Loop
End Sub

in UserForm1 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 2
fs.pstate = 1
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

in UserForm2 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 3
fs.pstate = 2
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

in UseFform3 module
Private Sub CommandButton1_Click()
Me.Hide
fs.nstate = 1
fs.pstate = 3
End Sub

Private Sub CommandButton2_Click()
Me.Hide
fs.nstate = fs.pstate
End Sub

keizi

Thank you for your patience with me!...I'll try your suggestion over
the weekend and hopefully fit it around my program...

Cheers...
 
C

Craig Coope

On Fri, 27 Apr 2007 21:53:54 +0900, "kounoike"

Thank you again and to Harlan for all your help...

I have managed to adjust the code you gave me so that my forms work
exactly as expect and now I only have one item in the call stack it
seems at all times so looks like my out of stack space is sorted...

I only have one more question now. With the code you gave me (and I
guess it makes sense by looking at it) it doesn't allow me to break
the program. Ie I can't press the X on the top right of the form.
(obviously pressing X closes the window and from the code in the
module it opens it back up again. What do I need to add to prevent
this?

Many Thanks again...
 
C

Craig Coope

On Fri, 27 Apr 2007 21:53:54 +0900, "kounoike"

Thank you again and to Harlan for all your help...

I have managed to adjust the code you gave me so that my forms work
exactly as expect and now I only have one item in the call stack it
seems at all times so looks like my out of stack space is sorted...

I only have one more question now. With the code you gave me (and I
guess it makes sense by looking at it) it doesn't allow me to break
the program. Ie I can't press the X on the top right of the form.
(obviously pressing X closes the window and from the code in the
module it opens it back up again. What do I need to add to prevent
this?

Many Thanks again...

Never mind...Sorted it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top