Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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.
0
et1dkn
Asked:
et1dkn
1 Solution
 
et1dknAuthor Commented:
Edited text of question
0
 
a111a111a111Commented:
Can you send the code to shayplace@hili.com
0
 
DalinCommented:
If possible, please post your code
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
viktornetCommented:
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
0
 
et1dknAuthor 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

0
 
mark2150Commented:
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.

0
 
deightonCommented:
Public Sub scope()
    bClear = True
    '
    '
    '
    '
    '
    '
    bClear = False
End Sub


'DECLARE bClear as a public variable
'
      '**************** 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:
          If Not (bClear) Then Call scope
      Case 187, 107:
          Z = Z * 2: If Z > 32 Then Z = 32
          cbZoomOut.Caption = Z
          cbZoomIn.Caption = ""
          Call ShowScale
          If Not (bClear) Then Call scope
      Case vbKeyA: If APFlg = True Then
      APFlg = False Else APFlg = True
             End If
             If Not (bClear) Then 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





0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now