Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / #include and the .dbproj file...

Author
Message
Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 8th Jul 2010 02:01
Ok, as I am now starting to lay down some Code, new questions arise. I am not going to start to try and create a serious application just yet; I am getting a feel for how to lay out a standard structure to any Projects I create.

In this respect, I have an issue with the #include Statement. I like the principle of controlling all Logic from Code.

Why is it there at all? As I understand it, it is used to 'include' another .dba file in the Project (I know that sounds like stating the bleedin' obvious, but bear with me...).

Now, the .dbproj File seems to include other .dba Files used in the Project automatically. I say seems, because that is my experience so far, but there may be issues that I am yet unaware of? I have even edited the .dbproj file manually and removed the include references, but when after saving/compiling, they are all back there again.

Hence my question, what's the point of #include Statements?

Furthermore, when I tried to run some Logic, the compiler told me to "**** off" (in Compiler speak ) when I tried this:

Main File:
------------------------
#include "inc.dba"
MyFunction()

------------------------

Included File (inc.dba):
------------------------
Function MyFunction()
Print "Blah blah blah"
EndFunction

------------------------

Now, if I remove the #include "inc.dba", the program runs just fine!

As if this wasn't enough, I tried the same thing with subroutines:

Main File:
------------------------
#include "sub.dba"
GOSUB MySubRoutine

------------------------

Included File (sub.dba):
------------------------
MySubRoutine:
Print "Blah Blah Blah"
RETURN

------------------------

This works whether I have the #include Statement or not!

But... when I try to use an included file with DATA, and try and READ it from the Main File, it compiles and runs without error, but nothing actually displays. Tried this:

Main File:
------------------------
#include "data.dba"
READ A$,B$,C$,D$,E$
Print A$,B$,C$,D$,E$

------------------------

Included File (data.dba)
------------------------
DATA "1","2","3","4","5"
------------------------

Whether I have the #include Statement or not, nothing prints to the screen at all.

I get the same if I do the same with a declaration:

Main File:
------------------------
#include "init.dba"
Print A$
Print B$

------------------------

Included File (init.dba):
------------------------
A$ = "Blah"
B$ = "Yadder"

------------------------

So is there a ruleset/reference that can tell me what does and doesn't work when it comes to the use of included file and/or #include?

I really like the idea of using included files as a means to structure modularly, and seems to me to be a useful way to handle big programs (which some of mine will become if I ever get that far).

Or have I missed something? (very possibly. I have only been dabbling with DBPro for a few days now...)

My objective was a structure along these lines:

#include "init.dba"
#include "data.dba"
#include "sub.dba"
#include "func.dba"

...Program Logic...

and even extend the use of included files if the weight of Code became very large or specific routine were needed, ie.

#include "menu.dba"
#include "DrawWorld.dba"
#include "RemindMeToMakeACupOfCoffee.dba"

and so on, so the structure begins to tak ehte form of a top down, hierarchical structure, with a simple Control Program at the Top, controlling Segments of Code (in their own Structures) as needed.

FOr those that have stuck with this so far, thank!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jul 2010 03:35
Quote: "Why is it there at all?"

It's a hold-over from the original DarkBasic Classic (DBC).

Whether you use the #INCLUDE directive or use the IDE to include extra files, either method will work in exactly the same way - the included file is appended to the main source file.

Your first example encounters a runtime error because after it has successfully called your function, it runs into the actual function itself. Add 'wait key' and 'end' commands just after the function call and you'll see it works fine.

Your second example with the subroutine appears to work because after calling the subroutine and returning, the very next statement is the subroutine again, and then a return which causes the program to return to where it was called from and so shutdown.

The third runs correctly, but because you haven't told it to pause anywhere, it exits after completing the instructions you have included.

The fourth example doesn't work as you expect because as I said above, included files are appended to the main file.

Hopefully I haven't missed anything there ... I should have just asked you to number everything

Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 8th Jul 2010 13:46
Doh! Now why didn't I think of that??? It seems so simple when you put it like that.

Basically, there's no need to use #include Statements at all.

That's another step forwards for me. And thanks!

However, just one more wee question:

In what order does the Compiler "Append" incuded files if you have more than one. In created order? In Name order? Inverted Egyptian Hieroglyph order? Can you change the order, i.e. by editing the .dbproj file?

May seem like a very minor detail. Possibly because it is, but...?
Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 8th Jul 2010 14:14
A quick aside... I get what I want by making an included file basically a subroutine. The order it is then processed in is in my control?

i.e.:

Main File:
----------------
Gosub init
Print A$
Print B$
...
----------------

Included file (init.dba):
----------------
init:
A$="Doh!"
B$="Mmmmmm..... Chocolate...."
return
----------------

And Bob's yer Auntie? A bit less clutter in the Main Program Logic, and a nice convenient file with all my declaration?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jul 2010 20:22 Edited at: 8th Jul 2010 20:25
Quote: "In what order does the Compiler "Append" incuded files if you have more than one."

For #INCLUDE, the files are included in the order they are encountered.

For project files, I'm not too sure, but I'd assume that they would be included in the same sequence as they are held within the .dbproj file, which for the latest IDE, is the order that they appear in the solution explorer panel.

Quote: "And Bob's yer Auntie?"

Yes, but consider how readable that is (or isn't in this case). Just because you can do it that way, doesn't mean that you should.

Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 9th Jul 2010 01:21
In this case quite happy to have another file with all the Declarations and Assignments (as part of setting up the general environment). It's dead easy to get at in the IDE, and it keeps a large chunk of Code out of the MAIN Program.

Seems to be working for me, but this is very early days yet.

I have just dropped the use of #include entirely. It is irrelevant. I make a Remark in the Header listing the files being included, but that is more for documentation (printed output) outside of the IDE.

My general aim it to have the MAIN File with Subroutines calls only. This may not be useful in every situation, but is a good basis to start from I think? Doing it like that sems to make it incredibly easy to see an overview of the Program.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 9th Jul 2010 09:19
Oh right, it seems it would be relevant to mention the # denotes a "precompiler" command, meaning it's done 1st thing - before the real code is compiled to an .exe


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 9th Jul 2010 14:03 Edited at: 9th Jul 2010 14:04
Quote: "# denotes a "precompiler" command, meaning it's done 1st thing"


Thanks. Exactly what I was looking for!

I take it by that if you do not have an #include in the Code, the Compiler will start with the Main Project File, and then work through the Included files in the order they are listed in the IDE (or in the .dbproj File)?.

The ability to use Included Project Files is damn useful to help with the organisation of the Source Code.

Login to post a reply

Server time is: 2024-09-28 18:24:15
Your offset time is: 2024-09-28 18:24:15