Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CHAIN command not working
#11
(08-09-2022, 06:09 AM)Pete Wrote: Back in the good ol' QJurassic Period, I put 14 programs together using a database file (what Steve was getting at) to transfer the data to each new program that was run from the main program. I never used CHAIN. I thought it was sucky and if I remember right, it had some limitations with stand-alone exes. So basically, you could say I yanked my CHAIN. I know Steve would happily put it that way!

Pete

...
using CHAIN to transfer the data from a program to another.... I miss the point, friend
CHAIN , like RUN, invokes a program and quit the invoking program.
The main difference and so the main advantage is to be able to transfer data from the invoking program to the invoked program... but it can be used just to run a program quitting the invoking program.

I think that the original reason to implement a CHAIN is just avoid the overflow (out of memory) error that it brings to crashing the program and loosing the data into it.
So in Qbasic using a memory stack pointed by the COMMON SHARED section in both the program files, the data present in the first program pass to the second program.
If Qbasic had had pointers (like C) the work would be done by them.

However
CHAIN needs 2 files .BAS or 2 files .EXE
please load into QB64 IDE these 2 files and pres f11 for each one, then go to the folder of QB64 (or where you have saved the 2 file .EXE) and click on PR1.EXE
Code: (Select All)
' program 1

Print "Hi, I'm the first to running"
Chain "Pr2.bas"

Code: (Select All)
' program 2

Print "Hi, I'm the second to running"
Print "Before me it runs Pr1.bas"

it seems to me that CHAIN have worked well.

Going deeper  we can add the COMMON area of data
we add a COMMON area of data to the two previous programs with output instructions to show the passed data.

Code: (Select All)
' program 3
Common a As Integer, b As Single, c As String
a = -11: b = 1.55: c = "QB64"
Print "Hi, I'm the first to running"
Print " I pass these values to Pr4.bas"
Print a, b, c
Print "Goodbye"
Chain "Pr4.bas"

Code: (Select All)
' program 4
Common integ As Integer, singl As Single, stri As String

Print "Hi, I'm the third to running"
Print "I get from Pr3.bas these values"
Print integ, singl, stri

as for the previous experiment, load code into data, save Program 3 as Pr3.bas, Program 4 as Pr4.bas
load each program into QB64 IDE and press F11.  At the end you go at folder of .EXE and run (doubleclick?) on Pr3.exe

Looking at results I must say that also in this case It works doing its job.

The only 2 rules that we must apply are:
1.-        .BAS with .BAS    or .EXE with .EXE  naturally both files must be in the same folder
2.-        if you use COMMON/ COMMON SHARED data the kind of data must be the same number in the same order in all file that use that COMMON area of data.

These my two cents
Reply
#12
Hi, there. Just thought I'd share my two cents. We discourage the use of CHAIN as it just uses a text file to read into the spawned program. However, using some sample code that I've written before, you can share memory between two programs in Linux and Windows. I will answer any questions someone might have about sharing variables between programs.


Attached Files
.bas   Shared_Memory_Parent.bas (Size: 1.6 KB / Downloads: 54)
.bas   Shared_Memory_Child.bas (Size: 1.26 KB / Downloads: 40)
.bas   Linux_Shared_Memory_Parent.bas (Size: 1.77 KB / Downloads: 33)
.bas   Linux_Shared_Memory_Child.bas (Size: 1.42 KB / Downloads: 38)
Tread on those who tread on you

Reply
#13
As a matter of fact, you can also just send and receive messages between two processes. Attached is some sample code. The "loremipsum.txt" is just used as data for the send and receive.


Attached Files
.txt   loremipsum.txt (Size: 1.88 KB / Downloads: 73)
.bas   Child Process.bas (Size: 1 KB / Downloads: 57)
.bas   Parent Process.bas (Size: 5.83 KB / Downloads: 51)
Tread on those who tread on you

Reply
#14
(08-31-2022, 01:28 PM)Spriggsy Wrote: Hi, there. Just thought I'd share my two cents. We discourage the use of CHAIN as it just uses a text file to read into the spawned program. However, using some sample code that I've written before, you can share memory between two programs in Linux and Windows. I will answer any questions someone might have about sharing variables between programs.

Hi Spriggsy,
very fine to see you.

1.
Yes I can confirm that the way of sharing data between 2 programs proposed by Spriggsy is very functional ( I tried successful it at the time of QB64.org)
I find interesting that the method has been shipped also to Linux SO.

2. 
I haven't yet tried to send and receive messagges between 2 programs on fly. But I think to try this as soon as I have time to learn (time with mind  rested)
Reply
#15
Hi,
ok, you guys - ok,ok you convinced me - i might do it via a database, stuff it into a file and extract it from there.
And besides - why not put it all in just ONE file?
Yeah ....
Thanks.
Udix
Reply




Users browsing this thread: 4 Guest(s)