Sambar Server Documentation

CScript #include


The #include statement includes and evaluates a specified file. For example, you can include ASP or C code from another file using the #include directives:
#include #include "foobar.asp"

would include foobar.asp and lib/mathlib.c into the current program. Any functions defined in the included file are available to the executing program and any code that is meant to execute is executed immediately (that is, any code found in the included file which is not inside a function block).

There is a subtle difference between using the #include directive with quotes (" ") versus the symbols (< >) inside the Sambar Server. When quotes are specified, the file is assumed to be relative to the current path of the currently executing script. So, if you are executing the script c:/docs/run.asp, the above include would look for foobar.asp in the c:/docs/ directory. The symbols (< >) direct the server to look for the file lib/mathlib.c relative to the installation directory of the Sambar Server. So if the server is installed in c:/sambar, the server will include c:/sambar/lib/mathlib.c in the above example. When using the bin/icscript executable, both directives map to the current working directory.

#include placement

In CScript, the #include directive can be placed inside a conditional expression. The following demonstrates the inclusion of an ASP snippet inside a for loop.
for (i = 0; i < 5; i++) { #include "foobar.asp" }

The above loop will include the foobar.asp script inside the for loop. All variables defined in the executing program are inherited by the included file foobar.asp, so the variable i could be used inside this snippet.

© 2001 Sambar Technologies. All rights reserved. Terms of Use.