Using Local Functions
A local function can be declared in the body of a script to avoid repetitions. However, as the body of a script at runtime is interpreted as the body of a function (see Supported Scripting Languages), not all languages allow declaring functions within functions.
JScript
JScript allows you to declare local functions without any restrictions. For example:
// Separation script (JScript)
function shouldProcess(block){
if(block.Text.indexOf("ABBYY")>=0){
return true;
return false;
}
function process(block){
// Do something with a block
}
for(var i = 0; i < this.TextBlocks.Count; i++){
var block = this.TextBlocks(i);
if(shouldProcess(block)){
process(block);
}
}
.NET
In .NET languages, you can use Lambda functions. For example:
// Separation script (C#)
System.Func<ITextBlock, bool> shouldProcess = (block)=>{
if(block.Text.IndexOf("ABBYY")>=0){
return true;
}
return false;
};
System.Action<ITextBlock> process = (block)=>{
// Do something with a block
};
foreach (ITextBlock block in page.TextBlocks){
if(shouldProcess(block)){
process(block);
}
}
VBScript
VBScript does not allow you to declare local functions, but you can use the ExecuteGlobal method to declare a global function or class.
3/26/2024 1:49:49 PM