Do fb compiler know join multiple parts of a file?

New to FreeBASIC? Post your questions here.
Post Reply
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Do fb compiler know join multiple parts of a file?

Post by Tourist Trap »

Hello,

This problem is really easy to understand. It would maybe be related to something like writting partial class in visual basic, but I'm not sure about that.

I want to be able to split any FB file, .bas or .bi, in many parts for clarity purpose, and I'm waiting the fb to be able to join the different parts before compiling.

A real example would be too long, take the following short version :

Code: Select all

''File SomeJobpart1.bas 
#include "SomeJobpart2"
#include "SomeJobpart3"
''
Dim inputVariable as object
Declare InputProcedure()
''
Sub InputProcedure()
    ''Get the inputs
End sub

Code: Select all

''File SomeJobpart2.bas 
#include "SomeJobpart1"
#include "SomeJobpart3"
''
Dim displayVariable as object
Declare DisplayProcedure()
''
Sub DisplayProcedure()
    ''Do the display job
End sub

Code: Select all

''File SomeJobpart3.bas 
#include "SomeJobpart1"
#include "SomeJobpart2"
''
''Global variables stand here all gathered together for clarity
Dim Shared GlobalVariable1 as object
Dim Shared GlobalVariable2 as object
''...
As far as I've been in my investigation, also playing with .bi files, I missed the trick. For long files, and in general for file management and viewing during coding, it would help me a lot to successfully divide the code. Not just a view splittilng, FBEdit does it well enought.


Thanks!
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Do fb compiler know join multiple parts of a file?

Post by grindstone »

Hello Tourist Trap!

It's quite simple. First change your examples to:

Code: Select all

''File SomeJobpart1.bas

Dim inputVariable as object
Declare Sub InputProcedure()
''
Sub InputProcedure()
    ''Get the inputs
End Sub

Code: Select all

''File SomeJobpart2.bas

Dim displayVariable as object
Declare Sub DisplayProcedure()
''
Sub DisplayProcedure()
    ''Do the display job
End Sub

Code: Select all

''File SomeJobpart3.bas

''Global variables stand here all gathered together for clarity
Dim Shared GlobalVariable1 as object
Dim Shared GlobalVariable2 as object
''...
and then (suggested they're all located in the root directory of drive E:) compile with:

fbc -s console E:\SomeJobpart1.bas E:\SomeJobpart2.bas E:\SomeJobpart3.bas

fbc will join the source files in the order they are mentioned in the command line.

Regards
grindstone
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Do fb compiler know join multiple parts of a file?

Post by D.J.Peters »

fbc *.bas
console wrote:d:\test>echo print "hello 3">test3.bas
d:\test>echo print "hello 2">test2.bas
d:\test>echo print "hello 1">test1.bas
d:\test>fbc *.bas
d:\test>test1
hello 3
hello 2
hello 1
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Do fb compiler know join multiple parts of a file?

Post by Tourist Trap »

grindstone wrote:(...)

fbc -s console E:\SomeJobpart1.bas E:\SomeJobpart2.bas E:\SomeJobpart3.bas

fbc will join the source files in the order they are mentioned in the command line.

Regards
grindstone
Invaluable tip.
Thanks a lot.
D.J.Peters wrote:fbc *.bas
It is less selective than previous example. Interesting anyway.

I still have to check my files to see if I manage to put all well together. I've also met difficulties with "include once", and so on. The fact is I've been trying to cut/paste the same, call that "startup sequence", at the top of each of the files of a single project awaiting for the compiler to link the good stuff when necessary. But this is not a too much important point.

Thanks again.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Do fb compiler know join multiple parts of a file?

Post by grindstone »

Invaluable tip.
I'm pleased that you like it, even so I would not recommend to do it this way, for it's much too inconvenient. It's by far easier to write a "master"-file like

Code: Select all

''File JobMaster.bas

#Include "SomeJobpart3.bas"
#Include "SomeJobpart1.bas"
#Include "SomeJobpart2.bas"
to do the joining in the right way. Please note the order of the included files: The very first thing that's done is defining the global variables, so the following parts can refer to them (otherwise you would get an error message "variable not defined"). Using #include is the same as to paste the contents of the mentioned file at this place.

Regards
grindstone
Post Reply