Archive

Archive for May, 2009

Debug VBScript with Visual Studio

May 21st, 2009 Frank 13 comments

For a project that I work on at at my primary employer, we use VBScript inside of DTS packages. Until this project, I’ve not had too much experience with VBScript. What I’ve found most frustrating about the language is the inability to step though the code… until a recent discovery. I’ve found that if I save the target code to my local machine as a VBS file and execute it with WScript.exe, I can attach a debugger to it.

I’ve discovered this by poking around and I don’t know too much about WScript.exe. I’m sure if you Google it, you can find more about it.

For this to work, you’ll need a copy of Visual Studio installed. I am not sure if any of the express editions will work. Drop a line in the comments if you find it will. As a quick walk though:

  1. Save your code as a VBS file. Don’t forget to call Main (or your main) function as wscript won’t automatically call main.
  2. Open a command prompt.
  3. Navigate to the location of the file.
  4. Type: WScript.exe FileName.vbs //D //X
  5. You should be prompted to select a debugger, select a new instance of either Visual Studio 2003, 2005 or 2008.
  6. Visual studio will open up and break at the very first line.
  7. Step though the code.

For an example, save the following as “Example.vbs” on your desktop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MsgBox "Starting Script!"
Dim i : i = 0
Const C_Max = 100
Dim sPrimeNumberList : sPrimeNumberList = "Prime Numbers: " & vbCrLf
For i = 0 to C_Max
  If IsNumberPrimeNumber(i) Then
     sPrimeNumberList = sPrimeNumberList & cStr(i) & ", "
  End If
Next
MsgBox sPrimeNumberList
MsgBox "Script Completed."

Public Function IsNumberPrimeNumber(ByVal iNumber)
Dim bIsPrime : bIsPrime = True
For j = 2 To iNumber\2
  bIsPrime = iNumber Mod j > 0
  If Not bIsPrime Then Exit For
Next
IsNumberPrimeNumber = bIsPrime
End Function

Open a command prompt and navigate to your desktop:

Command Prompt for Debugging VBScript from Visual Studio

Command Prompt for Debugging VBScript from Visual Studio

Once there, type in the following:

1
 wscript Example.vbs //D //X

You should then be presented with a dialog similar to the following:

Visual Studio Debugging VBScript

Visual Studio Debugging VBScript

Once you make a selection, you should get something like the following:

Debugging VBScript from Visual Studio

Debugging VBScript from Visual Studio

From here, I’ll assume you are familiar enough with Visual Studio to play with the debugger and learn how it works. When debugging VBScript, I’ve found that you don’t have all the options that you might be used to such as Step In To, but for me simply having this much is a life saver.

To get around the step-in-to thing, I simply use Run to Cursor. It works like a charm.

Update: I just found that (at least on this computer) and in Visual Studio 2003, I have all my standard code-stepping buttons available. I’m not sure why on my work computer I only have Step-Over but either way, this is still a life saver.

Undocumented Methods in NSIndexPath – Row, Section

May 11th, 2009 Frank No comments

Did you know that the NSIndexPath object apparently has undocumented properties / methods? I’m working on a hobby iPhone OS Application that I hope to release and I’ve been trying to figure out how to use the instances of indexPath provided by: tableView:cellForRowAtIndexPath:

Full protocol:

1
2
tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath

I was flipping though my iPhone Dev book and was reminded that we have a section method in the instances of indexPath. I just wanted to post this here because this is (at this time) not on apple’s documentation.

Thus far, there are two that I want to mention: section and row.  Both of these most iPhone developers will know about… except if you are new at this… Then this can be perplexing…

1
2
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];

Great SQL Server Tip

May 8th, 2009 Frank No comments
Categories: SQL Server Tags: ,

Windows 7 RC Available

May 6th, 2009 Frank No comments

Any one that would care probably knows already but the Windows 7 RC is available for Microsoft.

You can get more information at: http://msdn.microsoft.com/en-us/evalcenter/dd353271.aspx

Categories: Random Tags: , ,