Documentation for the usage of the Dlrsoft dll's

May 3, 2010 at 3:55 AM

Is there any way to get the documentation of the Dlrsoft dll's so that I can create a sample to test if the ASP Classic Compiler can be a potential replacement of the highly used MSScript.ocx control that I use for scripting support in my applications.

Coordinator
May 3, 2010 at 6:20 AM
We don't have any document on how to use VBScript.net outside of asp classic compilers yet. I will try to create one when I get sometime and release some sample code.

From: [email removed]
Sent: Sunday, May 02, 2010 7:55 PM
Subject: Documentation for the usage of the Dlrsoft dll's [aspclassiccompiler:211335]

From: manthangogari

Is there any way to get the documentation of the Dlrsoft dll's so that I can create a sample to test if the ASP Classic Compiler can be a potential replacement of the highly used MSScript.ocx control that I use for scripting support in my applications.

May 3, 2010 at 6:31 AM

That would be highly appreciated. If you can guide me regarding how to use the core Dlrsoft.VBScript module. All i want to do is be able to execute any VBScript that the user types in the text box. Below is an example Say a user wants to add two numbers x and y and he writes the following VB Script:

Dim num1

Dim num2

Dim num3

num1 = 1

num2= 1

num3 = num1 + num2

Then how do I pass this VBScript code to the Dlrsoft.VBScript module so that it compiles it and then executes it. I did the following:

 

try          

 {    

     ScriptRuntimeSetup setup = new ScriptRuntimeSetup();    

    setup.LanguageSetups.Add(new LanguageSetup(typeof(VBScriptContext).AssemblyQualifiedName, "vbscript", new[] { "vbscript" }, new[] { ".vbs" }));

    ScriptRuntime runtime = new ScriptRuntime(setup);  

    ScriptEngine engine = runtime.GetEngine("vbscript");

     runtime.LoadAssembly(typeof(VBScriptContext).Assembly); 

     ScriptScope scope = engine.CreateScope();

      StringBuilder code = new StringBuilder(); 

      code.AppendLine("Dim num1"); 

      code.AppendLine("Dim num2");      

       code.AppendLine("Dim num3");

       code.AppendLine("num1 = 1"); 

        code.AppendLine("num2 = 1"); 

        code.AppendLine("num 3 = num1 + num2");

         ScriptSource source = engine.CreateScriptSourceFromString(code.ToString(), SourceCodeKind.File);

         CompiledCode compiledCode = source.Compile();    

         object result = compiledCode.Execute();

         txtResults.Text = result.ToString();

      } 

     catch (Exception ex)    

       {  

             MessageBox.Show(ex.Message);    

       }

 

But when the program executes compiledCode.Execute() i get the following error. "cannot bind member, num, on object Microsoft.Scripting.ScopeStorage"

Can you tell me what am I missing here as I want to use the Dlrsoft.VBScript as a script engine that will execute VB scripts entered by the user and give the results of the script.

Any assistance would be highly appreciated.

May 3, 2010 at 6:43 AM

i did do some more change to the code changed the line 

code.AppendLine("num 3 = num1 + num2");

to 

code.AppendLine("num3 = num1 + num2");

but now the result is null. Do not know if the VBScript is getting executed or not. Is there a way to find out if the code was compiled and it got executed. Does the Execute() method give the results of the execution of the VBScript?

Coordinator
May 3, 2010 at 4:40 PM
Looks like you have fugured out how to use the hosting interface :)
 
The reason that it returned null is because it does not return the execution result of the last line as the return of the entire script.
 
To output result, you can either use System.Console.WriteLine(Num3). You would need to add an extra line "Imports System" at the beginning of your VBScript.
 
Alternatively, you can do scope["num3"] = null in your C# code to create the variable in your script scope. Do not dim it in your VBScript. VBScript.net compiler will then resolve to the script scode. You can read the results from scope["num3"] after execution. This will allow you to have multiple input/output variables.
 
Li

On Sun, May 2, 2010 at 10:43 PM, manthangogari <notifications@codeplex.com> wrote:

From: manthangogari

i did do some more change to the code changed the line 

code.AppendLine("num 3 = num1 + num2");

to 

code.AppendLine("num3 = num1 + num2");

but now the result is null. Do not know if the VBScript is getting executed or not. Is there a way to find out if the code was compiled and it got executed. Does the Execute() method give the results of the execution of the VBScript?

Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


May 4, 2010 at 12:45 AM
thanks for the assitance.

On Tue, May 4, 2010 at 1:40 AM, dotneteer <notifications@codeplex.com> wrote:

From: dotneteer

Looks like you have fugured out how to use the hosting interface :)
 
The reason that it returned null is because it does not return the execution result of the last line as the return of the entire script.
 
To output result, you can either use System.Console.WriteLine(Num3). You would need to add an extra line "Imports System" at the beginning of your VBScript.
 
Alternatively, you can do scope["num3"] = null in your C# code to create the variable in your script scope. Do not dim it in your VBScript. VBScript.net compiler will then resolve to the script scode. You can read the results from scope["num3"] after execution. This will allow you to have multiple input/output variables.
 
Li

On Sun, May 2, 2010 at 10:43 PM, manthangogari <notifications@codeplex.com> wrote:

From: manthangogari

i did do some more change to the code changed the line 

code.AppendLine("num 3 = num1 + num2");

to 

code.AppendLine("num3 = num1 + num2");

but now the result is null. Do not know if the VBScript is getting executed or not. Is there a way to find out if the code was compiled and it got executed. Does the Execute() method give the results of the execution of the VBScript?

Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Sincerely,

Manthan Gogari
May 10, 2010 at 5:43 AM

Hello Li,

I tried doing what you mentioned above by creating a variable and assign it as null and then execute the script and then try to read the variable value from the ScriptScope but there are few issues. if i do the following ScriptScope.SetVariable("var",null); I get ArgumentNullException stating that the value cannot be null. So then I implemented it as follows: ScriptScope.SetVariable("var", string.Empty); and then execute the script and try to read the value of the variable after the Execution of the script but the value of the variable remains empty string and not changed to what is mentioned in the script. Am I missing something. Below is the sample code that I am using.

 

VBScriptHost    scriptHost  = ( (App)Application.Current ).ScriptHost;

ScriptScope     scope       = scriptHost.CreateScope();  

string vbScript = "variable= \"Test1\"";

CompiledCode compiledCode = scriptHost.Compile( vbScript );

scope.SetVariable("variable", string.Empty);

compiledCode.Execute( scope );

object result = scope.GetVariable( "variable" );

txtResults.Text = result.ToString();

Apr 30, 2011 at 3:45 AM

I'm also experiencing this issue. Was there any resolution to it?

Coordinator
Apr 30, 2011 at 5:16 AM
The current implementation does not allow you to set to host variables. This will prevent people to redefine host variables with VBScript like “Response = 1”. What you can do is supply a host object and call the methods of the host object from your VBScript code. Look at the VBScriptTest project or VBSC project for example.
From: [email removed]
Sent: Friday, April 29, 2011 7:45 PM
To: [email removed]
Subject: Re: Documentation for the usage of the Dlrsoft dll's [aspclassiccompiler:211335]

From: coallen

I'm also experiencing this issue. Was there any resolution to it?

Apr 30, 2011 at 2:10 PM

Yes, thanks for the quick reply. I just figured that out (because one of your example projects was setting an object property so it had to work somehow!).