vbs error

Jan 19, 2014 at 7:26 PM
hello, i have this script:
Public Sub Run()
    clr.System.Windows.Forms.MessageBox.Show("hello world")
End Sub
but clearscript give me the error: Statement completion expected

what is in the script wrong?
Jan 19, 2014 at 9:25 PM
There doesn't seem to be anything wrong with the script. The following works in our testing and displays the message box as expected:
using (var engine = new VBScriptEngine())
    engine.AddHostObject("clr", new HostTypeCollection("System.Windows.Forms"));
        Public Sub Run()
            clr.System.Windows.Forms.MessageBox.Show(""hello world"")
        End Sub
Could there be a problem with the way you're loading or executing the script?
Jan 20, 2014 at 3:13 PM
Namespace conflicts with 'HostType' at 'System.Internal.HandleCollector'
 Engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
             Engine.AddHostObject("host", new HostFunctions());
             var typeCollection = new HostTypeCollection("mscorlib", "System", "System.Core", "System.Windows.Forms"); 
             Engine.AddHostObject("clr", typeCollection);
             Engine.Execute("var System = clr.System;");
             Engine.AddHostObject("require", new Action<string>(s => Engine.Execute(File.ReadAllText(Application.StartupPath + "\\Content\\" + s))));
             Engine.AddHostObject("eval", new Action<string>(s => Engine.Execute(s)));
             Engine.AddHostObject("xHost", new ExtendedHostFunctions());
Jan 20, 2014 at 4:19 PM
Edited Jan 20, 2014 at 4:19 PM
Yeah, this happens because mscorlib.dll includes a type named "System.Internal", and System.Windows.Forms.dll includes a namespace with the same name, so you can't merge them into the same type collection.

There are two things you can do - (1) use two separate type collections, or (2) use a filter to exclude types you don't need. The conflict here involves only internal types that probably aren't useful. Here's how to include only public types and avoid the conflict:
Predicate<Type> filter = type => type.IsPublic;
var collection = new HostTypeCollection(filter, "mscorlib", "System.Windows.Forms");
Good luck!
Jan 20, 2014 at 4:38 PM
the error Statement completion expected comes again
Jan 20, 2014 at 5:49 PM
Hmm, we still can't reproduce that. Where is the script coming from, and how are you loading it?
Jan 20, 2014 at 5:58 PM
it comes from a file, i load with file,readalllines
Jan 20, 2014 at 6:24 PM
Edited Jan 20, 2014 at 6:45 PM
OK, that gets you an array of strings; what do you do with them next? It would be great if you could post the code you use to load and execute the script.
Jan 20, 2014 at 6:28 PM
Jan 20, 2014 at 6:54 PM
Thanks for posting your code. Where is it failing? A stack trace might help. What script is it executing when it fails?
Jan 20, 2014 at 7:03 PM
that errors is here: Engine.Execute("Dim System = clr.System");
Jan 20, 2014 at 7:14 PM
That syntax is invalid in VBScript. Please see here and here.
Jan 20, 2014 at 7:17 PM
oh thanks it works