SetOutput (NoCallback)Method

Applies to:uCalc Transform
Class:uCalc
Formats the appearance of results returned by EvalStr or EvaluateStr
Syntax
SetOutput(Definition)
Parameters
Definition
String
Format definition for the output
Returns
Type: Item
Formats the appearance of results returned by EvalStr or EvaluateStr
Remarks
This function lets you modify the output returned by EvalStr or EvaluateStr. The definition may contain one or more of the following:

Datatype: If you specify a data type, then the modification will affect only the evaluation result of expressions that evaluate to the specified data type.

InsertAt: By default, if you define multiple outputs, then the one defined most recently is applied first, followed by the other outputs in reverse order in which they were defined, ending with the output that was defined first. You may specify a different insertion point than the default with this parameter.

Expression: This represents what the modified output should look like. The expression consists of an identifier (any temporary variable name) , followed by an equal sign, followed by a string expression representing the value that will be returned. The variable holds the original value that would have been returned.

Example 1: Output formating without using a callback

' The output is surrounded by < and >, and prepended with Answer:
uc.SetOutput("Result = 'Answer: <' + Result + '>'")
Console.WriteLine(uc.EvalStr("10+20")) ' Returns "Answer: <30>"
Console.WriteLine(uc.EvalStr("'Hello '+'world'")) ' Returns "Answer: <Hello world>"
Console.WriteLine(uc.EvalStr("5 > 10")) ' Returns "Answer: <false>"

          

// The output is surrounded by < and >, and prepended with Answer:
uc.SetOutput("Result = 'Answer: <' + Result + '>'");
Console.WriteLine(uc.EvalStr("10+20")); // Returns "Answer: <30>";
Console.WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Answer: <Hello world>";
Console.WriteLine(uc.EvalStr("5 > 10")); // Returns "Answer: <false>";

uc.ResetOutput();

          

         // The output is surrounded by < and >, and prepended with Answer:
         uc.SetOutput('Result = "Answer: <" + Result + ">"');
         WriteLn(uc.EvalStr('10+20')); // Returns 'Answer: <30>';
         WriteLn(uc.EvalStr('"Hello "+"world"')); // Returns 'Answer: <Hello world>';
         WriteLn(uc.EvalStr('5 > 10')); // Returns 'Answer: <false>';

          

// The output is surrounded by < and >, and prepended with Answer:
uc.SetOutput("Result = 'Answer: <' + Result + '>'");
cout << uc.EvalStr("10+20") << endl; // Returns "Answer: <30>";
cout << uc.EvalStr("'Hello '+'world'") << endl; // Returns "Answer: <Hello world>";
cout << uc.EvalStr("5 > 10") << endl; // Returns "Answer: <false>";

uc.ResetOutput();

          

// The output is surrounded by < and >, and prepended with Answer:
uc.SetOutput("Result = 'Answer: <' + Result + '>'");
Console::WriteLine(uc.EvalStr("10+20")); // Returns "Answer: <30>";
Console::WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Answer: <Hello world>";
Console::WriteLine(uc.EvalStr("5 > 10")); // Returns "Answer: <false>";

uc.ResetOutput();

          
Example 2: Different output formats for different data types

' String results will be surrounded by << and >>, while Boolean will be surrounded by [[ and ]]
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ")
uc.SetOutput("Bool, val = '[[' + val + ']]'"): ' Shortcut notation without "DataType" or "Def"
Console.WriteLine(uc.EvalStr("10+20")) ' Returns "30"
Console.WriteLine(uc.EvalStr("'Hello '+'world'")) ' Returns "<<Hello world>>"
Console.WriteLine(uc.EvalStr("5 > 10")) ' Returns "[[false]]"
Console.WriteLine(uc.EvalStr("5 < 10")) ' Returns "[[true]]"

          

// String results will be surrounded by + and >>, while Boolean will be surrounded by [[ and ]]
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("Bool, val = '[[' + val + ']]'"); // Shortcut notation without "DataType" or "Def"         
Console.WriteLine(uc.EvalStr("10+20")); // Returns "30";
Console.WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "<<Hello world>>";
Console.WriteLine(uc.EvalStr("5 > 10")); // Returns "[[false]]";
Console.WriteLine(uc.EvalStr("5 < 10")); // Returns "[[true]]";

uc.ResetOutput();

          

         // String results will be surrounded by + and >>, while Boolean will be surrounded by [[ and ]]
         uc.SetOutput('DataType: String, Def: val = "<<" + val + ">>" ');
         uc.SetOutput('Bool, val = "[[" + val + "]]"'); // Shortcut notation without 'DataType' or 'Def'         
         WriteLn(uc.EvalStr('10+20')); // Returns '30';
         WriteLn(uc.EvalStr('"Hello "+"world"')); // Returns '<<Hello world>>';
         WriteLn(uc.EvalStr('5 > 10')); // Returns '[[false]]';
         WriteLn(uc.EvalStr('5 < 10')); // Returns '[[true]]';

          

// String results will be surrounded by << and >>, while Boolean will be surrounded by [[ and ]]
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("Bool, val = '[[' + val + ']]'"); // Shortcut notation without "DataType" or "Def"         
cout << uc.EvalStr("10+20") << endl; // Returns "30";
cout << uc.EvalStr("'Hello '+'world'") << endl; // Returns "<<Hello world>>";
cout << uc.EvalStr("5 > 10") << endl; // Returns "[[false]]";
cout << uc.EvalStr("5 < 10") << endl; // Returns "[[true]]";

uc.ResetOutput();

          

// String results will be surrounded by + and >>, while Boolean will be surrounded by [[ and ]]
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("Bool, val = '[[' + val + ']]'"); // Shortcut notation without "DataType" or "Def"         
Console::WriteLine(uc.EvalStr("10+20")); // Returns "30";
Console::WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "<<Hello world>>";
Console::WriteLine(uc.EvalStr("5 > 10")); // Returns "[[false]]";
Console::WriteLine(uc.EvalStr("5 < 10")); // Returns "[[true]]";

uc.ResetOutput();

          
Example 3: Inserts formatting in specified sequence

uc.SetOutput("Result = 'Answer: ' + Result")
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ")
uc.SetOutput("DataType: Bool, Def: val = '[[' + val + ']]'")

' Note the difference between where "Bool: " and "String: " are displayed in the result
uc.SetOutput("InsertAt: 0, DataType: Bool, Def: val = 'Bool: ' + val"): ' Inserts at 0th position of Bool
uc.SetOutput("InsertAt: 1, DataType: String, Def: val = 'String: ' + val"): ' Inserts at 1st position of String
Console.WriteLine(uc.EvalStr("10+20")) ' Returns "Answer: 30"
Console.WriteLine(uc.EvalStr("'Hello '+'world'")) ' Returns "Answer: String: <<Hello world>>"
Console.WriteLine(uc.EvalStr("5 > 10")) ' Returns "Bool: Answer: [[false]]"

' This fomratting will be the last one to take effect
uc.SetOutput("InsertAt: 0, Def: val = 'Outer: ' + val")
Console.WriteLine(uc.EvalStr("10+20")) ' Returns "Outer: Answer: 30"
Console.WriteLine(uc.EvalStr("'Hello '+'world'")) ' Returns "Outer: Answer: String: <<Hello world>>"
Console.WriteLine(uc.EvalStr("5 > 10")) ' Returns "Outer: Bool: Answer: [[false]]"

' This formatting will be the first one to take effect
uc.SetOutput("val = 'Inner: ' + val"): ' Optionally InsertAt: -1 could have been used
Console.WriteLine(uc.EvalStr("10+20")) ' Returns "Outer: Answer: Inner: 30"
Console.WriteLine(uc.EvalStr("'Hello '+'world'")) ' Returns "Outer: Answer: String: <<Inner: Hello world>>"
Console.WriteLine(uc.EvalStr("5 > 10")) ' Returns "Outer: Bool: Answer: [[Inner: false]]"

          

uc.SetOutput("Result = 'Answer: ' + Result");
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("DataType: Bool, Def: val = '[[' + val + ']]'");

// Note the difference between where "Bool: " and "String: " are displayed in the result
uc.SetOutput("InsertAt: 0, DataType: Bool, Def: val = 'Bool: ' + val");  // Inserts at 0th position of Bool
uc.SetOutput("InsertAt: 1, DataType: String, Def: val = 'String: ' + val"); // Inserts at 1st position of String
Console.WriteLine(uc.EvalStr("10+20")); // Returns "Answer: 30";
Console.WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Answer: String: <<Hello world>>";
Console.WriteLine(uc.EvalStr("5 > 10")); // Returns "Bool: Answer: [[false]]";

// This fomratting will be the last one to take effect
uc.SetOutput("InsertAt: 0, Def: val = 'Outer: ' + val");
Console.WriteLine(uc.EvalStr("10+20")); // Returns "Outer: Answer: 30";
Console.WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Outer: Answer: String: <<Hello world>>";
Console.WriteLine(uc.EvalStr("5 > 10")); // Returns "Outer: Bool: Answer: [[false]]";

// This formatting will be the first one to take effect
uc.SetOutput("val = 'Inner: ' + val"); // Optionally InsertAt: -1 could have been used
Console.WriteLine(uc.EvalStr("10+20")); // Returns "Outer: Answer: Inner: 30";
Console.WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Outer: Answer: String: <<Inner: Hello world>>";
Console.WriteLine(uc.EvalStr("5 > 10")); // Returns "Outer: Bool: Answer: [[Inner: false]]";

uc.ResetOutput();

//+++E: Changing default settings
/*{{
      var OriginalSettings = uc.Default();
      Console.WriteLine(OriginalSettings.GetDataType().Name()); // Returns 0;
      uc.Define("Default ~~ DataType: Int32");
      uc.DefineFunction("f(x, y) = (x + y)/2");
      uc.DefineFunction("g(x) = x*100");
      Console.WriteLine(uc.EvalStr("f(5, 10)")); // Returns 0;
      Console.WriteLine(uc.EvalStr("g(5.1)")); // Returns 0;
      uc.Define("Default", 0, OriginalSettings.Handle()); // Restore original settings
   }}*/

ErrorHandler_(); 
ErrRaiseMsgTest(); 

ErrRaiseTest(); 

HandleTest(); 

TwiceStr(); 
//uc.Release(); //+++   
//var Testt = 1;
FPEnvRaiseTest(); 

Area(); 
MyAverage(); 
DisplayArgs(); 
MyFunctionCallback(); 
EvaluateCallback(); 
OutputCallback(); 

uc.Release();
uc.uCalcHandle = uCalcPrevHandle;
Console.WriteLine("The End");
} // End Examples

          

         uc.SetOutput('Result = "Answer: " + Result');
         uc.SetOutput('DataType: String, Def: val = "<<" + val + ">>" ');
         uc.SetOutput('DataType: Bool, Def: val = "[[" + val + "]]"');

         // Note the difference between where 'Bool: ' and 'String: ' are displayed in the result
         uc.SetOutput('InsertAt: 0, DataType: Bool, Def: val = "Bool: " + val');  // Inserts at 0th position of Bool
         uc.SetOutput('InsertAt: 1, DataType: String, Def: val = "String: " + val'); // Inserts at 1st position of String
         WriteLn(uc.EvalStr('10+20')); // Returns 'Answer: 30';
         WriteLn(uc.EvalStr('"Hello "+"world"')); // Returns 'Answer: String: <<Hello world>>';
         WriteLn(uc.EvalStr('5 > 10')); // Returns 'Bool: Answer: [[false]]';

         // This fomratting will be the last one to take effect
         uc.SetOutput('InsertAt: 0, Def: val = "Outer: " + val');
         WriteLn(uc.EvalStr('10+20')); // Returns 'Outer: Answer: 30';
         WriteLn(uc.EvalStr('"Hello "+"world"')); // Returns 'Outer: Answer: String: <<Hello world>>';
         WriteLn(uc.EvalStr('5 > 10')); // Returns 'Outer: Bool: Answer: [[false]]';

         // This formatting will be the first one to take effect
         uc.SetOutput('val = "Inner: " + val'); // Optionally InsertAt: -1 could have been used
         WriteLn(uc.EvalStr('10+20')); // Returns 'Outer: Answer: Inner: 30';
         WriteLn(uc.EvalStr('"Hello "+"world"')); // Returns 'Outer: Answer: String: <<Inner: Hello world>>';
         WriteLn(uc.EvalStr('5 > 10')); // Returns 'Outer: Bool: Answer: [[Inner: false]]';

          

uc.SetOutput("Result = 'Answer: ' + Result");
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("DataType: Bool, Def: val = '[[' + val + ']]'");

// Note the difference between where "Bool: " and "String: " are displayed in the result
uc.SetOutput("InsertAt: 0, DataType: Bool, Def: val = 'Bool: ' + val");  // Inserts at 0th position of Bool
uc.SetOutput("InsertAt: 1, DataType: String, Def: val = 'String: ' + val"); // Inserts at 1st position of String
cout << uc.EvalStr("10+20") << endl; // Returns "Answer: 30";
cout << uc.EvalStr("'Hello '+'world'") << endl; // Returns "Answer: String: <<Hello world>>";
cout << uc.EvalStr("5 > 10") << endl; // Returns "Bool: Answer: [[false]]";

// This fomratting will be the last one to take effect
uc.SetOutput("InsertAt: 0, Def: val = 'Outer: ' + val");
cout << uc.EvalStr("10+20") << endl; // Returns "Outer: Answer: 30";
cout << uc.EvalStr("'Hello '+'world'") << endl; // Returns "Outer: Answer: String: <<Hello world>>";
cout << uc.EvalStr("5 > 10") << endl; // Returns "Outer: Bool: Answer: [[false]]";

// This formatting will be the first one to take effect
uc.SetOutput("val = 'Inner: ' + val"); // Optionally InsertAt: -1 could have been used
cout << uc.EvalStr("10+20") << endl; // Returns "Outer: Answer: Inner: 30";
cout << uc.EvalStr("'Hello '+'world'") << endl; // Returns "Outer: Answer: String: <<Inner: Hello world>>";
cout << uc.EvalStr("5 > 10") << endl; // Returns "Outer: Bool: Answer: [[Inner: false]]";

uc.ResetOutput();

//+++E: Changing default settings
/*{{
      auto OriginalSettings = uc.Default();
      cout << OriginalSettings.GetDataType().Name() << endl; // Returns 0;
      uc.Define("Default ~~ DataType: Int32");
      uc.DefineFunction("f(x, y) = (x + y)/2");
      uc.DefineFunction("g(x) = x*100");
      cout << uc.EvalStr("f(5, 10)") << endl; // Returns 0;
      cout << uc.EvalStr("g(5.1)") << endl; // Returns 0;
      uc.Define("Default", 0, OriginalSettings.Handle()); // Restore original settings
   }}*/

ErrorHandler_(); 
ErrRaiseMsgTest(); 

ErrRaiseTest(); 

HandleTest(); 

TwiceStr(); 
//uc.Release(); //+++   
//auto Testt = 1;
FPEnvRaiseTest(); 

Area(); 
MyAverage(); 
DisplayArgs(); 
MyFunctionCallback(); 
EvaluateCallback(); 
OutputCallback(); 

uc.Release();
uc.uCalcHandle = uCalcPrevHandle;
cout << "The End" << endl;
} // End Examples

          

uc.SetOutput("Result = 'Answer: ' + Result");
uc.SetOutput("DataType: String, Def: val = '<<' + val + '>>' ");
uc.SetOutput("DataType: Bool, Def: val = '[[' + val + ']]'");

// Note the difference between where "Bool: " and "String: " are displayed in the result
uc.SetOutput("InsertAt: 0, DataType: Bool, Def: val = 'Bool: ' + val");  // Inserts at 0th position of Bool
uc.SetOutput("InsertAt: 1, DataType: String, Def: val = 'String: ' + val"); // Inserts at 1st position of String
Console::WriteLine(uc.EvalStr("10+20")); // Returns "Answer: 30";
Console::WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Answer: String: <<Hello world>>";
Console::WriteLine(uc.EvalStr("5 > 10")); // Returns "Bool: Answer: [[false]]";

// This fomratting will be the last one to take effect
uc.SetOutput("InsertAt: 0, Def: val = 'Outer: ' + val");
Console::WriteLine(uc.EvalStr("10+20")); // Returns "Outer: Answer: 30";
Console::WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Outer: Answer: String: <<Hello world>>";
Console::WriteLine(uc.EvalStr("5 > 10")); // Returns "Outer: Bool: Answer: [[false]]";

// This formatting will be the first one to take effect
uc.SetOutput("val = 'Inner: ' + val"); // Optionally InsertAt: -1 could have been used
Console::WriteLine(uc.EvalStr("10+20")); // Returns "Outer: Answer: Inner: 30";
Console::WriteLine(uc.EvalStr("'Hello '+'world'")); // Returns "Outer: Answer: String: <<Inner: Hello world>>";
Console::WriteLine(uc.EvalStr("5 > 10")); // Returns "Outer: Bool: Answer: [[Inner: false]]";

uc.ResetOutput();

//+++E: Changing default settings
/*{{
      auto OriginalSettings = uc.Default();
      Console::WriteLine(OriginalSettings.GetDataType().Name()); // Returns 0;
      uc.Define("Default ~~ DataType: Int32");
      uc.DefineFunction("f(x, y) = (x + y)/2");
      uc.DefineFunction("g(x) = x*100");
      Console::WriteLine(uc.EvalStr("f(5, 10)")); // Returns 0;
      Console::WriteLine(uc.EvalStr("g(5.1)")); // Returns 0;
      uc.Define("Default", 0, OriginalSettings.Handle()); // Restore original settings
   }}*/

ErrorHandler_(); 
ErrRaiseMsgTest(); 

ErrRaiseTest(); 

HandleTest(); 

TwiceStr(); 
//uc.Release(); //+++   
//auto Testt = 1;
FPEnvRaiseTest(); 

Area(); 
MyAverage(); 
DisplayArgs(); 
MyFunctionCallback(); 
EvaluateCallback(); 
OutputCallback(); 

uc.Release();
uc.uCalcHandle = uCalcPrevHandle;
Console::WriteLine("The End");
} // End Examples

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="SetOutput_Overload_uCalc_NoCallback")> _

Private Function SetOutput_Overload_uCalc_NoCallback__(ByVal uCalcHandle As IntPtr,ByVal Definition As String) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="SetOutput_Overload_uCalc_NoCallback")]

protected static extern IntPtr SetOutput_Overload_uCalc_NoCallback_(IntPtr uCalcHandle, string Definition);
            
{DLLImport}function SetOutput_Overload_uCalc_NoCallback__(uCalcHandle: System.Pointer;Definition: AnsiString): System.Pointer; cdecl; external uCalcDLL name 'SetOutput_Overload_uCalc_NoCallback';

            
typedef uCalcPtr (* __SetOutput_Overload_uCalc_NoCallback)(void *uCalcHandle, CONSTCHAR Definition ); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "SetOutput_Overload_uCalc_NoCallback")]

static uCalcPtr SetOutput_Overload_uCalc_NoCallback_(void *  uCalcHandle, MARSHALSTR Definition);
            
Prev | Next