Procedures before the calls?

Everything else that doesn't fall into one of the other PB categories.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Procedures before the calls?

Post by AMpos »

I have a program with a procedure:

Code: Select all

PROCEDURE TEST()
 debug("Test")
ENDPROCEDURE

TEST()
This code works, but this one, does not:

Code: Select all

TEST()

PROCEDURE TEST()
 debug("Test")
ENDPROCEDURE
I used (on other languages) to place PROCEDURES at the end of the source, for easier readiblity, but this has no sense for me. Is this really how PB works, or it is just me missing something?

My real problem/program is that now I have a proyect with multiples sources (listed in this order in proyect window)

SIDE1.pb
MAIN.pb
SIDE2.pb

Main can call procedures in SIDE1, but not in SIDE2 (and SIDE1 can not call procedures in SIDE2). Also, I dont know how to change the "order of compilation". If I add another source to my proyect, it is added in the last position, making it useless for the rest of the sources...
User avatar
Kiffi
Addict
Addict
Posts: 1358
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Procedures before the calls?

Post by Kiffi »

Declare is your friend:
PB-Help wrote:Sometimes a procedure need to call another procedure which isn't declared before its definition. This is annoying because the compiler will complain 'Procedure <name> not found'. Declare can help in this particular case by declaring only the header of the procedure. Nevertheless, the Declare and real Procedure declaration must be identical (including the correct type and optional parameters, if any).

Code: Select all

Declare TEST()

TEST()

PROCEDURE TEST()
 debug("Test")
ENDPROCEDURE
Hygge
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: Procedures before the calls?

Post by AMpos »

Thanks! Good to know.
Post Reply