We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Stack Space Problems

et1dkn
et1dkn asked
on
Medium Priority
227 Views
Last Modified: 2010-04-30
Using VB4.........
I have a procedure with the code enclosed in a DO-LOOP.
The proceduret plots points on the form and then draws a rotating cursor for the full 360 degrees.....then loops and repeats. Total time for the complete loop is approx 5 secs.
I detect keypress in a standard keypress event for some additional plotting during the first part of the loop.  After the code executes in the keypress event, I have to call the loop event again to be able to start at the beginning of the do-loop in order to immediately update the display. Detecting the keypress left the procedure return on the stack.....Now I have called the procedure again...This occurs each time I detect the Keypress.....eventually resulting in an Out of Stack Space error!  If I do not call the procedure at the end of the keypress code execution, (depening on how far in the 5 second loop I'm at) it could be up to 5 seconds before the results of the keypress code update the screen....Believe I have looked at this so long, I cant see the trees for the forest. Will appreciate anyone chastising me for not seeing the solution.
Comment
Watch Question

Author

Commented:
Edited text of question
Can you send the code to shayplace@hili.com

Commented:
If possible, please post your code
How about if you set a BREAK statement inside the loop if a key has been pressed and then start the loop again???

If you supply the code you are using we might be able to help you =)

Regards,
Viktor Ivanov

Author

Commented:
Many Thanks to those of you that have shown interest in this (problem).
Due to timing and speed constraints, I am attempting to stay away of
convuluted coding utilizing dual forms, redrawing in memory, etc.
which results in flicker  (IF POSSIBLE).
The Code is lengthy.....let me attempt to show skeleton code first....
(First Run.....Code has not been cleaned yet-bloated for readability)

Private Sub Scope()
Do      'BEGIN LOOP
ATCScope.Cls
'CLEAR THE SCOPE DISPLAY

For A = 1 To MAP
Call SetCen
'DATA COMES FM ARRAY LOADED
'FM DATA FILE.
'VARIOUS POINTS ARE
'PLOTTED ON SCREEN
Y = (Lat - Val(AP(A, 3))) * (MpdY * Z)
X = (Lon - Val(AP(A, 4))) * (MpdX * Z)      
Circle Step(X, Y), 3 * Z                  
Circle Step(0, 0), 1
If APFlg Then PSet Step(0, 0)
ForeColor = vbYellow
Print AP(A, 1)
ForeColor = ScopeFC                  
Next A                              
'THE APFLAG
'(DISPLAYING AND'ERASING A DESCRIPTOR)             
'OF POINTS PLOTTED IS ONE OF SEVERAL
'FLAGS SET BY CODE FROM
'THE KEYPRESS EVENT.

For A = 1 to ..........            
      .                        
      .
      .      
Next A                        

'SEVERAL OTHER FOR/NEXT LOOPS
'PLOTS POINTS FROM OTHER DATA.

**** DISPLAY ROTATING CURSOR ******
For A = 320 To 640                        
'DEFINES X-Y CO-ORDS
'FOR LINE STATEMENT
ATCScope.Line (CenX, CenY)-(A, 0), vbWhite      
For B = 1 To SwpSpd: DoEvents: Next B            
'SETS SPEED OF ROT.CURSOR
ATCScope.Line (CenX, CenY)-(A, 0), ScopeBC      
'ERASE CURRENT LINE
Next A

'MORE FOR-NEXT LOOPS CONTINUE DISPLAYING
'CURSOR FOR FULL 360 DEGREES.IN PRACTICE,
'VARIABLE SwpSpd GENERATES 5 TO 7 SECONDS
'DURATION BEFORE DO-LOOP RESTARTS.
      .
      .
      .
Loop

End Sub
'**************** KEYDOWN AND KEYPRESS EVENTS ****************
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 189, 109:
    Z = Z / 2: If Z < 1 Then Z = 1
    cbZoomIn.Caption = Z
    cbZoomOut.Caption = ""
    Call ShowScale: Call Scope
Case 187, 107:
    Z = Z * 2: If Z > 32 Then Z = 32
    cbZoomOut.Caption = Z
    cbZoomIn.Caption = ""
    Call ShowScale: Call Scope
Case vbKeyA: If APFlg = True Then
       APFlg = False Else APFlg = True
       End IF      
       Call Scope
'*****************************************
'ROOT PROBLEM...IF CALL TO SCOPE
IS MADE,(SCOPE PROCEDURE
'HAS NOT FINISHED--IT IS LEFT ON TOP OF CALLS LIST)
'BUT SCREEN IS UPDATED IMMEDIATELY.
'OVER LIFE OF APP, REPEATED BRANCHING TO KEYDOWN
'EVENT AND FURTHER CALL TO SCOPE RESULT IN OUT OF
'STACK SPACE ERROR.
'******************************************
Case ......
      .
      .'OTHER KEYDOWN EVENTS
      .
End Select
End Sub

Commented:
Simplest method would be to have a Global (or at least form level) boolean var that is set by the keypress routine and tested by the do loop to know when to exit. This prevents stack funnies and opens the door to multiple event routines being able to suspend DO.

prog
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.