#199627 - 2010-08-19 11:24 AM
Re: How to include functions?
[Re: Mart]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
As Mart has said if you define the functions in the main script then they are accessible in the sub-scripts, if you define the functions in the sub-script then they are available in the main script. Functions have a global scope.
There are a couple of things to be watch out for:
- If you are using SetOption("Explicit","ON") then don't CALL the scripts which define the UDF more than once, otherwise you will get an error when the script attempts to define the function a second time.
- When you define a function in a script it doesn't matter where it is defined - commonly people define them at the end of the script. However if you move the functions into a seperate file then you must CALL the file before you use the functions in the main script.
You can get around this restriction by using INCLUDE instead of CALL. INCLUDE loads the file during the parsing phase so the sub-script then appears to be part of the main script and processing acts as if it was one single file.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|