Nesting AFL code using #include statements

I am trying to nest AFL files using #include. The following code fragments distill the issue I am encountering.

// Sample1.AFL has the following code and is in the INCLUDE folder
X = 3;
function getX()
{
return X;
}

// Sample2.AFL has the following code and is also in the INCLUDE folder
// Both Sample1 and Sample2 work fine.
#include <Sample1.afl>
Y = getX();
function getY()
{
return Y;
}

// Sample3.AFL has the following code and is stored in the FORMULAS/Custom folder
#include <Sample1.afl>
#include <Sample2.afl>

B = getY();


The second include in Sample3.AFL generates errors. When I swap the two includes
in Sample3, the second one generates errors.

What I am trying to do is modularize the code.

Any insight or help would be most appreciated!

Best,

Gary

@GaryB you didn't write what kind of errors do you receive, but you should rethink the logic of your include statements. For example in your Sample3.AFL you only need to use: #include <Sample2.afl> because it already includes Sample1.afl

https://www.amibroker.com/guide/afl/_include.html
https://www.amibroker.com/guide/afl/_include_once.html

BTW - when pasting the code, use code tags. Read here:

2 Likes

You are declaring function getX() two times if applying Sample3.afl.

It would be the same as doing below one in Sample3.afl. Then you would get error 31 too (see below picture).

// this is alternative Sample3.afl without using #include command
// resulting in same error 31 (& 32) message

X = 3;
function getX()
{
   return X;
}

// #############################
// now the same one for a second time
X = 3;
function getX()
{
   return X;
}

// #############################

Y = getX();
function getY()
{
  return Y;
}

// #############################

B = getY();

You either have to remove #include <Sample1.afl> in your Sample3.afl or replace #include command by #include_once command in Sample2.afl and Sample3.afl.

159


A related thread

1 Like