Linking two programs

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Linking two programs

Post by Pete »

Have at it, guys!
name: Russell L. Meyers

Comments: Hi Pete,

Is it possible to link a two programs together e.g., one program which is a Transportation Planner and the other is a Transportation List. Can you place a link between the two so you don't have to execute each one separately. Would I have to make a menu within the Transportation Planner executing the Transportation List so that it gathers the database file which has all the information in it from the Transportation Planner program. I hope I didn't confuse you. You see, the information of the Departure, Destination and so on is in the database files called Tranplan.db which is opened by the Transporation List program and then printed to the screen or printer all the information that is in that database file. I'm just trying to figure out if I can just use one program to enter the data and then list it. Just curious.

Thx. Russ ;-) Happy Programming!
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

for this example I'll assume the following.
  • The database is in the same directory as the two executables.
    I'll omit any details on how tranplan.db is written or loaded.
    That you have the source code of both programs.
    That you want to do this in QB
Once the transporation planner has written the file you can simply, after that, enter a SHELL "tranlist.exe" at the end of the code and the second program should execute as it should.

If you don't have the source code, and just wondering how to execute to executables one after the other. You could create a batch file that would have

TRANPLAN.EXE
TRANLIST.EXE

And that would execute the programs. All you'd have to do is execute the batch file instead of the exe.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Linking Programs

Post by Zim »

In addition to Shell, you can also use the Chain statement, or the Run statement. Of course, this only works if you have the source for each program and you can modify and re-compile them.

"Shell" will simply hold the current program in memory and allow the operating system to begin execution of the other program. When finished, the operating system will return to the next line in the original program.

"Run" will cause one basic program to terminate and execute another. There's no coming back. The advantage is that all memory used by the first program is freed up to be used by the second.

"Chain" is like run, but even more interesting. You can have arrays and variables dimensioned in a "common" area such that when the second program is started it has access to the values stored in those variables.

Years ago I worked in a dialect of Basic on the HP4000 mini-computer. That BASIC had an "Invoke" statement that executed another BASIC program as a subroutine. I wish QB had something like that! You can fake it with "Chain" however.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
Post Reply