didn't qBasic have Proceedures rather than SubRoutines or Functions, which are kinda different to both.
Quote: "And how does DBPro support subroutines? Can you call a subroutine where you can pass in parameters? I don't see it being documented anywhere in the manual. And don't try to tell me GOSUB is calling a subroutine because it isn't. It's merely branching to a label."
Quote: "Surely a function without a return value is by definition, a sub-routine?"
... erm guys there is a clue within the name ...
SUB (Background/Underneath)
ROUTINE (Section of Repeated Code)
a SubRoutine & Functions are different kettles of fish entirely, and they're used identically as to how they are within VisualC++
a SubRoutine is a section of code which is kept seperate from the main section of code and can be called many times within...
i as dword
do
gosub Add
if i>=10 then exit
loop
Add:
i = i + 1
return
although yes this could be encapsulated within a function, all that the Subroutine actually is ... is a section of code which is part of the main Routine technically - it is just jumped to whenever you call it, the code will immediate jump back afterwards.
It is still part of the main code though and cannot be transfered or altered, kinda like a static function if you will. But it does have some inherint advantages over an actual function.
The main being that they don't actually take up any memory when they're being run, a function will be shifted into the memory using its own section of memory for the values it uses during its term - a subroutine doesn't require any memory to process as it only uses already declared values which are currently present within the memory ... this means you can use them inside/outside of funciton encapsulation.
MyValue as dword // this can be used within the main routine and sub routines
Global MyValue as dword // this can also be used in function
Local MyValue as dword // this is destoryed whenever a new instance is created, which means if it is create outside of a loop it is only valid uptil that loop. if it is created inside a subroutine it is valid until the loop loops. if it is created inside a function it retains full encapsulation.
anything created inside a function is automatically encapsulated unless you tell it otherwise. (this didn't used to be completely true, but was fixxed in the latest patches)
#constant's are just inlines - swap one thing for another, e.g.
#constant CUBE make object cube (m_pObject=m_pObject+1)
CUBE,10.0 `//will create a new cube size 10.0
you can actually get extremely complex with them, especially if you interlink them - but i'd be careful as it only really likes 1 level of inline code.
Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!