Daylight

Two uses of DO METHODs in Dynamic Scripting with Quadient Inspire

There are following two ways to use do methods:

#1) If the script is passed as an input string, then we can use do.eval() method to evaluate that script.

Declaration:

do.eval (Type aResultType, String aScript) : ResultType

This method compiles (at runtime) and executes a script passed as a string, and returns the result in the specified type. This allows the creation of script based on requirements only known at runtime. For example, complex validation or calculation rules can be read from a file / database or built up during runtime. The return type is specified in the first parameter.

Example:
String x;
x=Input.toString()+”.0/10″;
return do.eval(Double,x);
(Here Input is an integer)

Output:
For Input=5, Output will be 0.5
For Input=15, Output will be 1.5

#2) If the script is stored in a text file, we can use do.evalFile() method to evaluate that script.

Declaration:

do.evalFile (Type aResultType, String aPath) : ResultType

Calls and executes a script saved in an external file. The first parameter specifies the script’s return type and the second one the path to that external script.

Example:
return do.evalFile(Int,”E:\GMC\do methods\script.txt”);

e.g. Write following function in a text file (script.txt)
Int a=45, b= 55;
Int i;
//Script for calculating HCF
if(a>b)
i=b;
else
i=a;
while(i>0)
{
if(a%i==0 and b%i==0)
return i;
i–;
}

Output:
For a=45 and b=55, HCF is 5.

LEAVE A REPLY

Enter Captcha Here : *

Reload Image

Web
Analytics