dear,
please use bellow code for your problem solution for string to calculate formula.
before it provide facility in VB Script
so now u can used SQL table Expression Datatype of column and calculate it
thanks.
Imagic Solution
www.imagicsolution.com
vijay.comp@gmail.com
class Program
{
static void Main(string[] args)
{
string formula = "(a+b)/c"; // Take it from the data base or whatever...
Console.WriteLine("Enter first number:");
string a = Console.ReadLine();
Console.WriteLine("Enter second number:");
string b = Console.ReadLine();
Console.WriteLine("Enter third number:");
string c = Console.ReadLine();
// Replace all letters with numbers
formula = formula.Replace("a", a).Replace("b", b).Replace("c", c);
// Evaluate the formula
Console.WriteLine("Formula: {0}\tResult: {1}", formula, Evaluate(formula));
Console.ReadLine();
}
public static double Evaluate(string expression)
{
DataTable table = new DataTable();
table.Columns.Add("myExpression", string.Empty.GetType(), expression);
DataRow row = table.NewRow();
table.Rows.Add(row);
return double.Parse((string)row["myExpression"]);
}
}
Mr. Vijay Movaliya
Imagic Solution
www.imagicsolution.com
Shanpricol, if this helps please login to Mark As Answer. | Alert Moderator