Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Code written with Scriptom looks great and is easy to read. Sure. But it may not be as easy to write as it is to read.  Where is the look-ahead help? Where is the integration with your favorite IDE? How do you get started writing code against COM objects, many of which have little or no online documentation?  In this rather short article, I talk about why Scriptom does not have IDE integration, along with some techniques and tools you can use to make COM programming with Scriptom much easier.

No IDE Integration for Scriptom

Let's start with IDE integration.  To make it short, there isn't any, and it isn't planned.  The trouble is, Scriptom uses "late bound" COM calls, exclusively.  Every COM object in Scriptom is just an ActiveXObject to Groovy.  Even at runtime, there is no reliable way to determine exactly what kind of an object you are working with under the covers.  Scriptom just passes along the method name, along with the arguments, and trusts that everything will go well. 

For those of us who are used to static typing, this may seem like a dangerous practice.  I think you will find, though, that it works surprisingly well.  It also simplifies things considerably.  Have you seen the number of COM wrappers that Microsoft.NET has to support?  Scriptom doesn't require a COM wrapper generator (though it does include a library of constant definitions).  You can just write your code and run it.

Scriptom uses the same calling mechanism that is used by Microsoft's typeless scripting languages, like VBScript and JScript.  It is also the calling convention that is used from Visual Basic 6 or VBA when you are working with an Object.  That is why they call it Scriptom.  It uses the calling convention that is usually used by scripting languages.

An Easier Way than Trial and Error

So if there is no IDE integration for Scriptom, how do you figure out the COM thing?  Here are some ideas, based on my own experience working with COM.

  • Use VB6 or VBA to browse the object models and write sample code. Visual Basic 6 and VBA have a nearly identical set of tools for browsing objects, setting references to COM libraries, and for look-ahead help.  Most COM libraries were designed to be compatible with Visual Basic, and those will usually work well with ScriptomVB6 is part of Visual Studio 6, which is scheduled to be desupported by Microsoft in 2008.  VBA is available as the macro language in all the Microsoft Office products, and in many other products as well.
    • Use Visual Studio.NET to browse the object model.  I don't recommend this over VB6/VBA because the support for COM is a little more obscure in the Microsoft.NET products.   However, in a pinch, it works, and the Visual Studio Express products are free.  
  • Buy a book.  There are many books available that cover COM APIs for specific products.  For example, a used copy of Excel 2002 VBA on Amazon would run you less the $15, including shipping.  When you are working with the really complex applications, like Excel and Word, I have always found it beneficial to have a second opinion.
  • Use the web to find examples.  Some people call it "Programming by Google."  If you want to do something, you can bet that some other fool has already done it and published it somewhere on the web.
  • Read the manual.  Use Microsoft's search tool at to find the official documentation.  Some of it is very good, some it will leave you with questions, but all of it is official.
  • Don't write code, write a macro.  For Microsoft Office applications that support macros, the macro language is VBA.  This means that when you create a macro, Word or Excel will actually write the code for you.  It is usually trivial to port VBA to Groovy/Scriptom.  This is an excellent way to figure out how to do obscure tasks in Office.

There.  That should get you started off on the right foot.  Enjoy!    


  • No labels