Solved

Stack Space Problems

Posted on 1998-09-12
7
189 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

785 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