VBscript C#

VBscript C#

k005
Advisor Advisor
753 Views
2 Replies
Message 1 of 3

VBscript C#

k005
Advisor
Advisor
        public double CalculFormula(string Formula)
        {

            MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
            sc.Language = "VBScript";

            try
            {
                return System.Convert.ToDouble(sc.Eval(Formula));
            }
            catch (System.Exception)

            {
                return 0;
            }

        }

 

 

private void button5_Click(object sender, EventArgs e)
{
lblsonuc.Text = CalculFormula(txtCalc.Text).ToString();
}

 

Hello

This code works fine when compiled as WindowsForm. When I compile it as a plug-in (.dll), it does not find any errors.

 

but when triggered with the button I get this error.

 

 

 

 

 

0 Likes
Accepted solutions (1)
754 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

As you have already known, as I replied in the other discussion forum, that Microsoft ScriptControl 1.0 is a 32-bit COM component. It being working in your .NET WinForm EXE is because your EXE is built against "any CPU" so that the .NET runtime automatically runs it as 32-bit app due to the fact the app uses a 32-bit component. If you rebuild your WinForm by targeting x64 CPU, you would have known it does not work.

 

Since you post this in AutoCAD .NET discussion forum, I assume you are trying to run the code in AutoCAD plugin, where your AutoCAD is 64-bit. If so, you CANNOT use this 32-bit ScriptControl. 

 

You may want to search for different scripting component that is pure .NET component (thus run on both x86 or x64 platforms).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

k005
Advisor
Advisor

@norman.yuan 

 

Thank you. 😔

0 Likes