Problem with addObject MSScript Control

scripting , csharp , .net Clearwater, United States
  • 11 years ago

    Hello,

    I am trying to add basic scripting functionality to my .Net application. I am using MSScript Control for the scripting. I want to add a list of varibles & its value to the script. I am not able to add a simple string variable to the script using AddObject method.

    Lets say I have something like this.

    public partial class Form1 : Form { public MSScriptControl.ScriptControlClass script = new MSScriptControl.ScriptControlClass();

        public String amount = "120";
    
        public Form1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
              script.Reset();
               object[] array = new object[] { };
              String Code = "Sub Main() MsgBox Amount End Sub";
    
            try
            {
                script.AddCode(Code);
                 script.AddObject("Amount", amount,true);
            }
            catch (System.Exception ex)
            {
    
            }
    
    
            try
            {
                script.Run("Main", ref array);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + " " + script.Error.Description);
            }
    
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            this.textBox1.Text = "MsgBox \"We are on inVoice Screen\"";
            script.AllowUI = true;
            script.Language = "VBScript";
        }
    }
    

    I get the error " Invalid procedure call or argument"

    Any help will be greatly appreciated.

  • 11 years ago

    Hello,

    I am trying to add basic scripting functionality to my .Net application. I am using MSScript Control for the scripting. I want to add a list of varibles & its value to the script. I am not able to add a simple string variable to the script using AddObject method.

    Lets say I have something like this.

    public partial class Form1 : Form { public MSScriptControl.ScriptControlClass script = new MSScriptControl.ScriptControlClass();

        public String amount = "120";
    
        public Form1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
              script.Reset();
               object[] array = new object[] { };
              String Code = "Sub Main() MsgBox Amount End Sub";
    
            try
            {
                script.AddCode(Code);
                 script.AddObject("Amount", amount,true);
            }
            catch (System.Exception ex)
            {
    
            }
    
    
            try
            {
                script.Run("Main", ref array);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + " " + script.Error.Description);
            }
    
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            this.textBox1.Text = "MsgBox \"We are on inVoice Screen\"";
            script.AllowUI = true;
            script.Language = "VBScript";
        }
    }
    

    I get the error " Invalid procedure call or argument"

    Any help will be greatly appreciated.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov