Author Topic: Returning from CHAIN Statement  (Read 3262 times)

0 Members and 1 Guest are viewing this topic.

Offline MarkSkits

  • Newbie
  • Posts: 3
    • View Profile
Returning from CHAIN Statement
« on: August 12, 2018, 02:23:54 pm »
I'm making another sort of interface in QBASIC, and it keeps running out of memory because it's in DOS. To fix this, I figured I'd separate the SUBs into different BAS/EXE files and just use a CHAIN statement, however, I cannot figure out how to have the secondary program return to the main program without restarting said main program. For example:

Main:
Code: QB64: [Select]
  1. CHAIN "calc.bas"
  2. lastRan = "Calculator"
  3. ...
  4.  

Calc.bas:
Code: QB64: [Select]
  1. TRUE = 1
  2. DO UNTIL exitProgram = TRUE
  3.     'Calculator Stuff
  4.     ...
  5. [return to main]
  6.  

Is it possible to have it return to where it was on the main program, and if so, how can I do so?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Returning from CHAIN Statement
« Reply #1 on: August 12, 2018, 09:22:49 pm »
You might look here.
http://qb64.org/wiki/CHAIN

though I would take a serious look at your code and see if there is anyway to resolve the memory issue. like making sure your not  GOSUBing and RETURNing. make sure your not over allocating when you don't need it.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Returning from CHAIN Statement
« Reply #2 on: August 12, 2018, 09:25:40 pm »
Ideally you'd make it all one single module (or at least one that uses included modules) instead of using CHAIN, since limitations of the past don't apply to QB64 anymore in regard to module size, but it seems you want Qbasic support on DOSbox, is that right?

In the occurrence you really are avoiding qb64 altogether, you'll have to chain back to the main program. You'll also probably need some COMMON variables to keep the program's state across CHAIN calls.

PS: QB64 does emulate CHAIN but doesn't use shared memory. All data transfer is done via a file on the disk.
« Last Edit: August 12, 2018, 09:28:25 pm by FellippeHeitor »