Method Initialize
Initialize(string, string, string, int, int, int)
Initializes the calculator to start calculating
Declaration
void Initialize(string inputRtf, string variables, string sectionName, int sectionId = 0, int pageWidth = 180, int pageHeight = 260)
Parameters
| Type | Name | Description |
|---|---|---|
| string | inputRtf | Optional input formatted in Microsoft Rich Text Format(RTF) which will be calculated |
| string | variables | Xml string of the variables to initialize the calculator with, usually created by GetVariables |
| string | sectionName | Calc Section name |
| int | sectionId | Calc Section unique numeric identifier |
| int | pageWidth | Output page width in twips, default is 180 twips |
| int | pageHeight | Output page height in twips, default is 260 twips |
Remarks
The initialize method is often used without any parameters, the optional parameters are required to run an existing calculation or to retrieve the final output, however also consider using InitializeCalc.
The inputRtf is required if you want to calculate an existing RTF source, for example if you wanted to integrate Tedds with an alternative word processor you would get the RTF from the document and pass it as this parameter so that Tedds would calculate the expressions in the RTF. The inputRtf is also required if you want to obtain output RTF once calculating is finished. Output is obtained by using the GetOutput method but if no inputRtf has been specified to the Initialize function (or the InitializeCalc function) then GetOutput will not return any output.
If the calculator has been used to perform a calculation and you want to save the variables so that they can be used for re-calculating then you can use the optional variables parameter to initialise the calculator with the previously saved variables. The variables from a previous calculation are retrieved by using the GetVariables function.
//Create calculator
ICalculator calculator = new Calculator();
//Initialize first time
calculator.Initialize();
//Set all required variables
calculator.functions.SetVar("L", 1500, "mm");
calculator.functions.SetVar("W", 750, "mm");
//Calculate an expression
double area = calculator.Functions.Eval("L * W").ToDouble("mm^(2)");