ParseMethod
Syntax
Parse(Expression, DataType)
Parameters
Expression
String
Expression to be parsed
DataType
String
(Default = 0)
Data type of return value
Example 1: Displaying a different result for each value of x based on the expression parsed with Parse
Dim VariableX = uc.DefineVariable("x")
Dim Expression As string
Console.Write("Enter an expression (Ex: x^2 * 10): ")
Expression = Console.ReadLine()
Dim ParsedExpr = uc.Parse(Expression)
Dim x As double
for x = 1 To 10
VariableX.SetVariableValue(x)
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.Evaluate())
Next
ParsedExpr.Release()
VariableX.Release()
var VariableX = uc.DefineVariable("x");
string Expression;
Console.Write("Enter an expression (Ex: x^2 * 10): ");
Expression = Console.ReadLine();
var ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.Evaluate());
}
ParsedExpr.Release();
VariableX.Release();
Write('Enter an expression (Ex: x^2 * 10): ')
Expression = ReadLn();
for x := 1 to 10 do
begin
VariableX.SetVariableValue(x);
WriteLn('x = ' + x + ' Result = ' + ParsedExpr.Evaluate());
End;
ParsedExpr.Release();
VariableX.Release();
auto VariableX = uc.DefineVariable("x");
string Expression;
cout << "Enter an expression (Ex: x^2 * 10): " << endl;
cin >> Expression;
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
cout << "x = " << x << " Result = " << ParsedExpr.Evaluate() << endl;
}
ParsedExpr.Release();
VariableX.Release();
auto VariableX = uc.DefineVariable("x");
string ^ Expression;
Console::Write("Enter an expression (Ex: x^2 * 10): ");
Expression = Console::ReadLine();
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console::WriteLine("x = " + x + " Result = " + ParsedExpr.Evaluate());
}
ParsedExpr.Release();
VariableX.Release();
Example 2: Displaying a different Integer (Int32) result for each value of x based on the expression parsed with Parse
Dim VariableX = uc.DefineVariable("x")
Dim Expression As string
Console.Write("Enter an expression (Ex: x / 2): ")
Expression = Console.ReadLine()
Dim ParsedExpr = uc.Parse(Expression, "Integer"):
Dim x As double
for x = 1 To 10
VariableX.SetVariableValue(x)
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateInt32())
Next
var VariableX = uc.DefineVariable("x");
string Expression;
Console.Write("Enter an expression (Ex: x / 2): ");
Expression = Console.ReadLine();
var ParsedExpr = uc.Parse(Expression, "Integer");
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateInt32());
}
ParsedExpr.Release();
VariableX.Release();
Write('Enter an expression (Ex: x / 2): ')
Expression = ReadLn();
for x := 1 to 10 do
begin
VariableX.SetVariableValue(x);
WriteLn('x = ' + x + ' Result = ' + ParsedExpr.EvaluateInt32());
End;
auto VariableX = uc.DefineVariable("x");
string Expression;
cout << "Enter an expression (Ex: x / 2): " << endl;
cin >> Expression;
auto ParsedExpr = uc.Parse(Expression, "Integer");
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
cout << "x = " << x << " Result = " << ParsedExpr.EvaluateInt32() << endl;
}
ParsedExpr.Release();
VariableX.Release();
auto VariableX = uc.DefineVariable("x");
string ^ Expression;
Console::Write("Enter an expression (Ex: x / 2): ");
Expression = Console::ReadLine();
auto ParsedExpr = uc.Parse(Expression, "Integer");
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console::WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateInt32());
}
ParsedExpr.Release();
VariableX.Release();
Example 3: displaying each character of a string on a separate line
Dim MyString As string
Console.Write("Enter an expression (Ex: 'This is a Test'): ")
MyString = Console.ReadLine()
Dim VariableX = uc.DefineVariable("x As Int32")
Dim MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString)
Dim ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)")
Dim StrLength = uc.Eval("Length(MyStringVar)")
Dim x As Int32
for x = 0 To StrLength-1
VariableX.SetVariableValueInt32(x)
Console.WriteLine(ParsedExpr.EvaluateStr())
Next
string MyString;
Console.Write("Enter an expression (Ex: 'This is a Test'): ");
MyString = Console.ReadLine();
var VariableX = uc.DefineVariable("x As Int32");
var MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
var ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
var StrLength = uc.Eval("Length(MyStringVar)");
for (Int32 x = 0; x <= StrLength-1; x++) {
VariableX.SetVariableValueInt32(x);
Console.WriteLine(ParsedExpr.EvaluateStr());
}
Write('Enter an expression (Ex: "This is a Test"): ')
MyString = ReadLn();
for x := 0 to StrLength-1 do
begin
VariableX.SetVariableValueInt32(x);
WriteLn(ParsedExpr.EvaluateStr());
End;
string MyString;
cout << "Enter an expression (Ex: 'This is a Test'): " << endl;
cin >> MyString;
auto VariableX = uc.DefineVariable("x As Int32");
auto MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
auto ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
auto StrLength = uc.Eval("Length(MyStringVar)");
for (int x = 0; x <= StrLength-1; x++) {
VariableX.SetVariableValueInt32(x);
cout << ParsedExpr.EvaluateStr() << endl;
}
string ^ MyString;
Console::Write("Enter an expression (Ex: 'This is a Test'): ");
MyString = Console::ReadLine();
auto VariableX = uc.DefineVariable("x As Int32");
auto MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
auto ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
auto StrLength = uc.Eval("Length(MyStringVar)");
for (int x = 0; x <= StrLength-1; x++) {
VariableX.SetVariableValueInt32(x);
Console::WriteLine(ParsedExpr.EvaluateStr());
}
Example 4: Displaying a different complex number result for each value of x based on the expression parsed with Parse
Dim x As double
Dim VariableX = uc.DefineVariable("x")
Dim Expression As string
Console.Write("Enter an expression (Ex: x * #i + 5): ")
Expression = Console.ReadLine()
Dim ParsedExpr = uc.Parse(Expression, "Complex"):
for x = 1 To 10
VariableX.SetVariableValue(x)
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateStr())
Next
ParsedExpr.Release()
VariableX.Release()
double x;
var VariableX = uc.DefineVariable("x");
string Expression;
Console.Write("Enter an expression (Ex: x * #i + 5): ");
Expression = Console.ReadLine();
var ParsedExpr = uc.Parse(Expression, "Complex");
for (x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console.WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateStr());
}
ParsedExpr.Release();
VariableX.Release();
Write('Enter an expression (Ex: x * #i + 5): ')
Expression = ReadLn();
for x := 1 to 10 do
begin
VariableX.SetVariableValue(x);
WriteLn('x = ' + x + ' Result = ' + ParsedExpr.EvaluateStr());
End;
ParsedExpr.Release();
VariableX.Release();
double x;
auto VariableX = uc.DefineVariable("x");
string Expression;
cout << "Enter an expression (Ex: x * #i + 5): " << endl;
cin >> Expression;
auto ParsedExpr = uc.Parse(Expression, "Complex");
for (x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
cout << "x = " << x << " Result = " << ParsedExpr.EvaluateStr() << endl;
}
ParsedExpr.Release();
VariableX.Release();
double x;
auto VariableX = uc.DefineVariable("x");
string ^ Expression;
Console::Write("Enter an expression (Ex: x * #i + 5): ");
Expression = Console::ReadLine();
auto ParsedExpr = uc.Parse(Expression, "Complex");
for (x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
Console::WriteLine("x = " + x + " Result = " + ParsedExpr.EvaluateStr());
}
ParsedExpr.Release();
VariableX.Release();
Example 5: Displaying an expression of unsigned byte as a signed byte by using a Pointer
Dim VariableX = uc.DefineVariable("x As Int")
Dim Expression As string
Console.Write("Enter an expression (Ex: x + 125): ")
Expression = Console.ReadLine()
Dim ParsedExpr = uc.Parse(Expression, "Int8u")
Dim x As Int32
for x = 1 To 10
VariableX.SetVariableValueInt32(x)
Console.WriteLine("x = " + x + " Int8 result = " + uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8"))
Next
var VariableX = uc.DefineVariable("x As Int");
string Expression;
Console.Write("Enter an expression (Ex: x + 125): ");
Expression = Console.ReadLine();
var ParsedExpr = uc.Parse(Expression, "Int8u");
for (Int32 x = 1; x <= 10; x++) {
VariableX.SetVariableValueInt32(x);
Console.WriteLine("x = " + x + " Int8 result = " + uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8"));
}
ParsedExpr.Release();
VariableX.Release();
Write('Enter an expression (Ex: x + 125): ')
Expression = ReadLn();
for x := 1 to 10 do
begin
VariableX.SetVariableValueInt32(x);
WriteLn('x = ' + x + ' Int8 result = ' + uc.ValueAt(ParsedExpr.EvaluateVoid(), 'Int8'));
End;
auto VariableX = uc.DefineVariable("x As Int");
string Expression;
cout << "Enter an expression (Ex: x + 125): " << endl;
cin >> Expression;
auto ParsedExpr = uc.Parse(Expression, "Int8u");
for (int x = 1; x <= 10; x++) {
VariableX.SetVariableValueInt32(x);
cout << "x = " << x << " Int8 result = " << uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8") << endl;
}
ParsedExpr.Release();
VariableX.Release();
auto VariableX = uc.DefineVariable("x As Int");
string ^ Expression;
Console::Write("Enter an expression (Ex: x + 125): ");
Expression = Console::ReadLine();
auto ParsedExpr = uc.Parse(Expression, "Int8u");
for (int x = 1; x <= 10; x++) {
VariableX.SetVariableValueInt32(x);
Console::WriteLine("x = " + x + " Int8 result = " + uc.ValueAt(ParsedExpr.EvaluateVoid(), "Int8"));
}
ParsedExpr.Release();
VariableX.Release();
Example 6: Performing a summation; a return value is needed only at the very end
Dim VariableX = uc.DefineVariable("x")
Dim Total = uc.DefineVariable("Total")
Dim Expression As string
Console.Write("Enter an expression (Ex: Total = Total + x^2 + 5): ")
Expression = Console.ReadLine()
Dim ParsedExpr = uc.Parse(Expression)
Dim x As double
for x = 1 To 10
VariableX.SetVariableValue(x)
ParsedExpr.Execute()
Console.WriteLine(uc.Eval("x") + " Sub total = " + uc.Eval("Total"))
Next
var VariableX = uc.DefineVariable("x");
var Total = uc.DefineVariable("Total");
string Expression;
Console.Write("Enter an expression (Ex: Total = Total + x^2 + 5): ");
Expression = Console.ReadLine();
var ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
ParsedExpr.Execute();
Console.WriteLine(uc.Eval("x") + " Sub total = " + uc.Eval("Total"));
}
Console.WriteLine("Total = " + uc.Eval("Total"));
ParsedExpr.Release();
VariableX.Release();
Write('Enter an expression (Ex: Total = Total + x^2 + 5): ')
Expression = ReadLn();
for x := 1 to 10 do
begin
VariableX.SetVariableValue(x);
ParsedExpr.Execute();
WriteLn(uc.Eval('x') + ' Sub total = ' + uc.Eval('Total'));
End;
auto VariableX = uc.DefineVariable("x");
auto Total = uc.DefineVariable("Total");
string Expression;
cout << "Enter an expression (Ex: Total = Total + x^2 + 5): " << endl;
cin >> Expression;
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
ParsedExpr.Execute();
cout << uc.Eval("x") << " Sub total = " << uc.Eval("Total") << endl;
}
cout << "Total = " << uc.Eval("Total") << endl;
ParsedExpr.Release();
VariableX.Release();
auto VariableX = uc.DefineVariable("x");
auto Total = uc.DefineVariable("Total");
string ^ Expression;
Console::Write("Enter an expression (Ex: Total = Total + x^2 + 5): ");
Expression = Console::ReadLine();
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x = x + 1) {
VariableX.SetVariableValue(x);
ParsedExpr.Execute();
Console::WriteLine(uc.Eval("x") + " Sub total = " + uc.Eval("Total"));
}
Console::WriteLine("Total = " + uc.Eval("Total"));
ParsedExpr.Release();
VariableX.Release();
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="Parse")> _
Private Function Parse__(ByVal uCalcHandle As IntPtr,ByVal Expression As String , ByVal DataType As String ) As IntPtr
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="Parse")]
protected static extern IntPtr Parse_(IntPtr uCalcHandle, string Expression , string DataType );
{DLLImport}function Parse__(uCalcHandle: System.Pointer;Expression: AnsiString ; DataType: AnsiString): System.Pointer; cdecl; external uCalcDLL name 'Parse';
typedef uCalcPtr (* __Parse)(void *uCalcHandle, CONSTCHAR Expression , CONSTCHAR DataType );
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "Parse")]
static uCalcPtr Parse_(void * uCalcHandle, MARSHALSTR Expression , MARSHALSTR DataType);