The metacommand $INCLUDE basically permit the main program to call another program and run the code in the 2nd program to the end before returning to the main program which called it.I don't agree if you don't agree that in the second program (file of code) there is only a block of code of the main (, or if you like this other version) i.e. the second program.BAS is only a main block of code.
n making multiple calls to the 2nd program, is there a way of having a common variable that can be changed during the course of running the main program?
a variable declared into the main of program and used in a block of main written in another file does it loose its content/value?
count = count + 1
PRINT count
’$INCLUDE:’File1.bas’
‘$INCLUDE:’File1.bas’
‘$INCLUDE:’File1.bas’
count = count + 1
PRINT count
count = count + 1
PRINT count
count = count + 1
PRINT count
DIM SHARED count
PRINT
PRINT "This is the main program"
PRINT "Jumping to the 2nd program'"
SLEEP
'
'COMMON SHARED count
'DIM SHARED count
count = count + 1
IF count = 3 THEN
PRINT "Now in Program 2 for 3rd time"
PRINT "Expect to Exit Program 2 now"
SLEEP
END
END IF
PRINT "Now in Program 2"
PRINT "This is the "; count; " number of times visiting Program 2"
SLEEP
PRINT
PRINT "Now back in the main program"
PRINT
PRINT "Going Back to the 2nd program"
'
'COMMON SHARED count
'DIM SHARED count
count = count + 1
IF count = 3 THEN
PRINT "Now in Program 2 for 3rd time"
PRINT "Expect to Exit Program 2 now"
SLEEP
END
END IF
PRINT "Now in Program 2"
PRINT "This is the "; count; " number of times visiting Program 2"
SLEEP
PRINT
IF count = 3 THEN
PRINT "Count is 3 - Back in main program for the 3rd time"
count = 4
END IF
PRINT "Now back in the main program for the 2nd time"
In this case I'm inserting the same block multiple times. What I was trying to do was to find a way to Exit the $Included block of text early. The only thing that came to mind was a Common variable that would trigger the Included block to end earlier rather than running the code to its end. I did expect, when the main and Included block of coding ran, that there was an automatic sharing of variables and I could avoid the issue of passing values as happens with Subs.
In my example programs, although both the main and the included have the same COUNT variable, the IF statement triggering the premature end of the Included file doesn't work. Or at least hasn't been working for me. I gather then that the coding in an $INCLUDE must run it's course unlike a Sub/Function which you can Exit early.