×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

OUT OF STACK SPACE is in our way!

OUT OF STACK SPACE is in our way!

OUT OF STACK SPACE is in our way!

(OP)
We at Titan Software are currently making a military strategy game for Qbasic, but we keep getting the message "Out of stack space." WHAT DO WE DO?

Also, if anyone has any solution to the Out Of Memory problem, that'd be helpful too.  If you need any more info let me know.

RE: OUT OF STACK SPACE is in our way!

(OP)
Out of Stack Space can be caused by two things: recursive functions and error handlers (ON ERROR GOTO).

To fix it, try this
CLEAR ,,32767

Note that this clears all of the memory variables, so you better put this before you declare any arrays. If it doesn't work, then you need to rewrite your program, so that it doesn't recurse so much (and use tons of stack space).

RE: OUT OF STACK SPACE is in our way!

Mr. Titan Software, it sounds as though you're using subroutines for every part of the program's functionality, and simply calling the next subroutine from each subroutine to move around (e.g., inside menus, etc.). If this is the case, your approach needs to be modified. My suggestion is that you change your SUBs into FUNCTIONs, and assign each of those FUNCTIONs a number. Then, have your main program look at the value that each function returns and use that to determine what the next FUNCTION to call is. Finally, instead of calling the FUNCTIONs from inside the FUNCTIONs, simply return the value corresponding to the next function to call. Example:

Old (broken) way:

DECLARE SUB choice1 ()
DECLARE SUB choice2 ()
DECLARE SUB menu1 ()
DECLARE SUB menu2 ()
DECLARE SUB promptForValue (a$)

'Main program
menu1

SUB choice1
PRINT "You selected choice #1!"
menu2
END SUB

SUB
choice2
PRINT "You selected choice #2!"
menu2
END SUB

SUB
menu1
DO
 PRINT
"1. Another menu"
 PRINT "2. Exit program"
 PRINT
 promptForValue a$
 SELECT CASE VAL(a$)
  CASE 1: menu2
  CASE 2: END
 END SELECT
LOOP
END SUB

SUB
menu2
DO
 PRINT
"1. Choice 1"
 PRINT "2. Choice 2"
 PRINT "3. Return to main menu"
 PRINT
 promptForValue a$
 SELECT CASE VAL(a$)
  CASE 1: choice1
  CASE 2: choice2
  CASE 3: menu1
 END SELECT
LOOP
END SUB

SUB
promptForValue (a$)
LINE INPUT "Enter a selection: ", a$
END SUB


New (working, better, more modular) way:

DECLARE FUNCTION choice1% ()
DECLARE FUNCTION choice2% ()
DECLARE FUNCTION menu1% ()
DECLARE FUNCTION menu2% ()
DECLARE FUNCTION promptForValue$ (a$)
CONST SELECTchoice1% = 1
CONST SELECTchoice2% = 2
CONST SELECTmenu1% = 3
CONST SELECTmenu2% = 4
CONST SELECTendProgram% = 5

'Main program
selection% = SELECTmenu1%
DO
 SELECT CASE
selection%
  CASE SELECTchoice1%:
   selection% = choice1%
  CASE SELECTchoice2%:
   selection% = choice2%
  CASE SELECTmenu1%:
   selection% = menu1%
  CASE SELECTmenu2%:
   selection% = menu2%
  CASE SELECTendProgram%:
   EXIT DO
 END SELECT
LOOP
END

FUNCTION
choice1%
PRINT "You selected choice #1!"
choice1% = SELECTmenu2%
END FUNCTION

FUNCTION
choice2%
PRINT "You selected choice #2!"
choice2% = SELECTmenu2%
END FUNCTION

FUNCTION
menu1%
DO
 PRINT
"1. Another menu"
 PRINT "2. Exit program"
 PRINT
 promptForValue a$
 SELECT CASE VAL(a$)
  CASE 1:
   menu1% = SELECTmenu2%
   EXIT FUNCTION
  CASE
2:
   menu1% = SELECTendProgram%
   EXIT FUNCTION
 END SELECT
LOOP
END FUNCTION

FUNCTION
menu2%
DO
 PRINT
"1. Choice 1"
 PRINT "2. Choice 2"
 PRINT "3. Return to main menu"
 PRINT
 promptForValue a$
 SELECT CASE VAL(a$)
  CASE 1:
   menu2% = SELECTchoice1%
   EXIT FUNCTION
  CASE
2:
   menu2% = SELECTchoice2%
   EXIT FUNCTION
  CASE
3:
   menu2% = SELECTmenu1%
   EXIT FUNCTION
 END SELECT
LOOP
END FUNCTION

SUB
promptForValue (a$)
LINE INPUT "Enter a selection: ", a$
END SUB


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close