Link to home
Start Free TrialLog in
Avatar of et1dkn
et1dkn

asked on

Stack Space Problems

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.
Avatar of et1dkn
et1dkn

ASKER

Edited text of question
Can you send the code to shayplace@hili.com
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
Avatar of et1dkn

ASKER

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

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.

ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial