Solved

Stack Space Problems

Posted on 1998-09-12
7
187 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.
0
Comment
Question by:et1dkn
7 Comments
 

Author Comment

by:et1dkn
ID: 1434545
Edited text of question
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1434546
Can you send the code to shayplace@hili.com
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1434547
If possible, please post your code
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:viktornet
ID: 1434548
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
 

Author Comment

by:et1dkn
ID: 1434549
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
 
LVL 12

Expert Comment

by:mark2150
ID: 1434550
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
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1434551
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now