C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


■103445 / )  Re[4]: C#で関数を含む計算式文字列を処理して計算する
□投稿者/ 星は昴 (8回)-(2024/11/21(Thu) 15:17:14)
No103442 (くま さん) に返信
> 2024/11/20(Wed) 16:03:36 編集(投稿者)
> 
> //----- テスト(開始)
>             EasyCalc EasyCalc1 = new EasyCalc();
>             EasyCalc1.Expression = "a + b + 3 + 4";
>             string values = "var a = 1; var b = 2;";
>             string error = string.Empty;
>             double result = EasyCalc1.GetValue(values, ref error);
>             Console.WriteLine("result:{0} error:{1}", result, error);
> 
>             // 使える計算式は以下のURLを参照      
>             // h t t p s ://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Math
>             EasyCalc1.Expression = "Math.log(1.5)";
>             values = string.Empty;
>             error = string.Empty;
>             result = EasyCalc1.GetValue(values, ref error);
>             Console.WriteLine("result:{0} error:{1}", result, error);
> //----- テスト(終了)

 ちょっと時間が取れなくて、教えてもらったコードを今確認しましたが、両方ともエラーが出ます。

private void btnCalc_Click(object sender, EventArgs e)
{
    EasyCalc EasyCalc1 = new EasyCalc();
    EasyCalc1.Expression = "a + b + 3 + 4";
    string values = "var a = 1; var b = 2;";
    string error = string.Empty;
    double result = EasyCalc1.GetValue(values, ref error);
    TbxOut.Text = String.Format("result:{0} error:{1}", result, error); //Console→TextBox
}
result:10 error:

private void btnCalc_Click(object sender, EventArgs e)
{
    EasyCalc EasyCalc1 = new EasyCalc();
    EasyCalc1.Expression = "Math.log(1.5)";
    string values = string.Empty;
    string error = string.Empty;
    double result = EasyCalc1.GetValue(values, ref error);
    TbxOut.Text = String.Format("result:{0} error:{1}", result, error);
}
result:0.405465108108164 error:

返信 編集キー/


管理者用

- Child Tree -