PRB: Out of Stack Space When One Modal Form Shows AnotherLast reviewed: June 21, 1995Article ID: Q103461 |
The information in this article applies to:
SYMPTOMSAny of the following error messages can occur when two or more forms in a program repeatedly show each other modally (SHOW 1).
CAUSEThis can happen even if you unload the form, which in turn shows the next form. A form is not actually unloaded by the Unload statement until all its event procedures return (End Sub or Exit Sub). Showing a form modally suspends execution and, like a procedure call, maintains information on the stack. Further explanation is given in the MORE INFORMATION section below.
WORKAROUNDS
MORE INFORMATIONThe following example gives an Out of stack space error message. Remove the apostrophe from (uncomment) the MsgBox statements in Visual Basic for MS-DOS to see the amount of remaining stack space.
' Form1: Sub Form_Click () ' MsgBox STR$(FRE(-2)) Unload Form1 Form2.Show 1 End Sub ' Form2: Sub Form_Click () ' MsgBox STR$(FRE(-2)) Unload Form2 Form1.Show 1 End SubWhen a function or a subroutine is called, the variables in the calling procedure get pushed onto the stack. This way these values are preserved. When the function or subroutine ends on an End Function, End Sub, or Exit Sub statement, these variables get popped off the stack, and programexecution returns to the statement that follows the call. Only then are the variables once again usable. If a subroutine or function calls another function, program execution is halted within that subroutine or function, and the stack used is not cleared up until an End Function, End Sub, or Exit Sub is encountered. This is why you should not have two subroutines repeatedly call each other with no stopping condition. The behavior of event procedures within forms is similar to subroutines in that when a form is shown, information is pushed onto the stack, and when forms are unloaded, information is popped off the stack. Modal forms halt program execution of all other events. However, a form is not actually unloaded by the Unload statement until all of its event procedures return with an End Sub or Exit Sub. When a modal form displays a second modal form, the second modal form puts a hold on program execution, so the first modal form cannot proceed to the rest of its code, thus making it impossible to ever reach the End Sub or Exit Sub statement. This is why you should not have modal forms show each other repeatedly.
|
Additional reference words: 1.00 2.00 3.00 B_VBMSDOS
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |