views:

32

answers:

2

I have the following VBScript:

Dim strFile, strXPath, strNewText, xmlDoc, xmlNodes, xmlNode

strFile = "C:\folder\cats.xml"
strXPath = "/list/cat/@LAST_BATH"
strNewText = Now

Set xmlDoc =  CreateObject("Microsoft.XMLDOM")

xmlDoc.Async = "False"
xmlDoc.Load(strFile)

Set xmlNodes = xmlDoc.selectNodes(strXPath)

For Each xmlNode in xmlNodes
  xmlNode.Text = strNewText
Next

xmlDoc.Save strFile

XML file:

<?xml version="1.0" ?>
<list>
  <cat NAME="Monkey" LAST_BATH="9/30/2010  3:02:02 PM" />
</list>

The above script is only 1KB. I also have a small C#.NET console app (.exe) that does exactly the same thing, but it is 11KB, and the App.config is 1KB (config file so the path and field name is not hard-coded).

What I intend to do is create a Scheduled Task to run the above process at some interval.

Which is better to use, the .vbs or the .exe? And why?

Does the difference in memory affect performance? I assume the .exe is faster because it is pre-compiled, but since the .vbs is so small, I'm guessing it's about as fast as you could ever want anyway.

(I realize this is a moot point, but I'm just curious. Thanks for you patience.)

+1  A: 

I'm definitely a fan of using scripting languages wherever possible for small tools and apps - this example is a perfect candidate:

  • Its not too complicated
  • As a script you can easily modify and tweak the script without needing to recompile
  • You can easily see what the script does without needing to hunt down the source code

Of course scripting languages are (probably) always going to be slower than compiled code, but usually I find this isn't really an issue.

If you write a lot of small tools like this in vbs then you might want to consider switching to a more capable scripting language - as a .Net developer I strongly recommend Iron Python (which works really well even for relatively large / GUI utilities)

Kragen
+1, thanks Kragen. *Omg Iron Python looks awesome!* Actually, I'd love to use a "better" scripting language, and I plan to learn Windows PowerShell soon. However, the reason that I am using VBScript currently (or .NET 2.0 .exes) is because my client doesn't have the latest environments, and it's a big deal even to get them to upgrade .NET frameworks. So for now, I program for the lowest common denominator.
JohnB
I was wondering, are there IDEs/debuggers for VBScript programming? Right now I write blindly and have to use a lot of `MsgBox`'s
JohnB
@JonB - Visual studio works quite well, and has an excellent VBScript debugger. The simplest way I know is to start the script with `cscript /D`, and place a `Stop` statement on the first line of the file (equivalent to `debugger;` in JavaScript).
Kragen
@JonB - If IronPython is out then you may alternatively want to consider JScript (coming from a web background I prefer JavaScript to VBScript)
Kragen
@JonB - This is also another good link / reference for script debugging - http://www.wilsonmar.com/1wsh.htm
Kragen
+1  A: 

There would be no issues in performance, since it's a small task. I would prefer VBS for that task. The source is easy to change and no compiling/linking needed. You can edit the code right on the directory you are working, unlike in compiled code wherein you need to access the project directory open VS and edit it there.

Ruel