.Net scripting

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
When VB came out, there was VB.Script, and a COM object to run VB.Script code and the ability to pass COM objects between the VB code and VB.script. Is there such a thing in the .Net world?

Or would I still be using VB Script and make my dot net objects Com wrappable and pass that between VB Script and Dot Net?

Does anybody have any insight?
 

Noobsa44

Member
Jun 7, 2005
65
0
0
There is a way of building .net scripts; however I wouldn't recommend it as it requires a lot more structure than a normal script does. There are scripting engines that wrap this complexity, but they come with their own flaws and aren't standard. You can do some fairly cool things to script using .net functionality in VB Script.

If you want base functionality, such as System.Collections.ArrayList, you can simply call set x = CreateObject("Name.Space") (See example below). While not all Namespaces have COM wrappers, many due. In order to find them all I suggest you use my script from a previous post (http://forums.anandtech.com/me...2111345&enterthread=y).

If you wish to create your own functionality, I know of at least one way to do it. If you create a installer, and include your DLL, you can register it for COM. I believe you will want to set the Register property to vsdrfCOM, but it has been a long time and I might be mistaken about that point. Keep in mind that not all types work well between COM and VBS. Keep in mind that I've not done this for a few years, but I don't believe that an array of strings passes well between .net and VBS, however an array of Objects works just fine (even if the objects are strings). Hopefully this will be helpful to you. If you have more questions on this subject, let me know as I did this for work for some years and became something of an expert in the subject. :)

Example VBS .net usage:

Dim list
Dim item
set list = CreateObject("System.Collections.ArrayList")
list.Add("Hi")
list.Add("Goodbye")
list.Add("Hello")
list.sort()
for each item in list
MsgBox item
next
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
(Ashamed to say this) We have enterprise level legacy applications that process thousands of transactions from within VBScript. In order to make the newer .NET stuff work, we end up writing COM wrappers all the time. The interoperability rules that apply to Java and .NET amalgamation, also apply to .NET and VBScript. In fact once you get the jist of it, writing a COM wrapper is really trivial. Make your assembly COM visible, register using regsvr32.exe for COM InterOp (Or choose from the Visual Studio IDE project settings to "generate an InterOp.dll) and pass objects back and forth as System.Object. You will be OK as long as you stick to native types. In some of our projects, we need to pass streams, which is impossible - there we put the legacy ADOStream object to use... convert using ADOStream to a byte array and pass to .NET as an object - casting it directly from within C# works like a charm.

As long as the actual scripting capabilities go (if you initial question was just for general knowledge), search for Script# - Nikhil Kothari, one of the major brains behind ASP.NET is working on this new "laguage" - it allows you to use the .NET API in C, and upon compilation, spits out raw JavaScript code. I think he is planning on providing a switch to spit out VBScript code, too.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
You can create script using PowerShell, which has a .net type interface.

I have used a tool called nscript and really like it. Really it is just a automatic compiler for a simple vb application, but it has proved useful so far.

http://www.codeproject.com/dotnet/nscript.asp
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
Thanks for the input guys. I will look at the options listed and see if any works for me!