Archive

Posts Tagged ‘VBScript’

Attaching Microsoft Script Debugger to a Running Process

October 7th, 2010 No comments

OK, I’ve just learnt how to do something that I’m going to find very useful in the future! I’ve wanted to do this for a while and didn’t know, but necessity is the mother of invention (or investigation in this case.)

Here’s the scenario. I have a running Internet Explorer session connected to a Live environment. I cannot change the Live code to add in a “Stop” statement. That Internet Explorer session is actually a hosted version of the IE ActiveX control inside of a custom executable. I have a VBScript bug and I need to see what’s happening.

So, what I need to do is to attached Microsoft Script Debugger (MSD) to the running IE session, and force a breakpoint in the code. Here’s how….

  1. Start MSD.
  2. Go to “Debug” -> “Processes”.
  3. Find the appropriate process, use the “Title” column to help.
  4. Click “Attach”.
  5. When the “Attach to Process” screen is displayed, click “OK”.
  6. Click “Close”

That will now attach you to the correct process. All you need to do now is to add a break point.

  1. Go to “Debug” -> “New Breakpoint”
  2. Type in the name of a function, sub-routine or event that you want to trap.
  3. Perform the actions in IE that would cause the function where you inserted the breakpoint to fire.
  4. You should then be directed to MSD with the source code of the lines where you inserted the break point.
  5. Step-Over, Out-of or Into as much as you’d like!

Simple really – just needed five minutes of Googling and playing around in MSD!

VBScript function IsNumeric

August 18th, 2009 No comments

Brilliant.

Last night, we discovered that the VBScript function “IsNumeric” is a little more clever than you’d like, but there’s also no simpler version either.

Consider the following scenario.

We have the user input in a bit of text on screen. We need to process that (client-side), and part of that processing needs to find out if it is a number or not (i.e. if it’s a number, do this, otherwise, do that.)

Last night, we encountered a problem with the word “65d1” – clearly, it’s not a number (the “d” gives that away,) however, IsNumeric says that it is. If you CInt(“65d1”) you get 650. WTF?

A little more testing reveals the following:

CInt("65d0")  => 65
CInt("65d1")  => 650
CInt("65d2")  => 6500
CInt("65d-1") => 6

So obviously that “d” refers to “*(10 ^ following number)” – however, I can’t find a reference for that.

A bit of googling turns up this page , which shows that adding a space at the front doesn’t stop it from being classed as numeric.

The only real clue to what is going on is to read, and interpret, the MSDN reference page which states:

Returns a Boolean value indicating whether an expression can be evaluated as a number.

And there-in lies the answer – that expression can be evaluated as a number, not that it is a number.

Fortunately, there is an implementation listed on the first page which shows you an alternative way to get the job done.

I’m now wondering if there are other things that you can enter that will affect an number in that way. I tried

CInt("6*5")

but that just errored. I’m wondering whether “e” has a similar effect.

Update: Yes, “e” (at first glance) appears to have an identical effect to “d”.

CInt("65D1") => 650
CInt("65D1") => 6500
CInt("65E1") => 650
CInt("65E1") => 6500

Debugging Client-Side VBScript

August 4th, 2009 No comments

Having used client-side VBScript for years at work, I discovered the joys of the Microsoft Script Debugger several years ago. Unfortunately, until now, I’ve been unable to get the debugger to invoke when I desired (rather than having to wait for a crash!)

Several times, I ran across web pages saying that you just type “debugger” – however that only works with Javascript and not VBScript. I also found loads of references to Server-side debugger with ASP.Net – again that doesn’t work with client side.

But, finally, today I managed to find an article which actually explains the process, and marvellously, it’s not difficult and it’s (logically) a one liner.

So I can reveal that to invoke the debugger in client-side VBScript, all you type is…..

stop

Huzzah!