• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

.Net scripting

brandonb

Diamond Member
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?
 
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
 
(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.
 
Back
Top