Sonntag, 22. März 2009

Using PowerShell to scan through Visual Basic Code

Perhaps you have some old VB6 Projects containing some SQL-queries in SQL-Server Syntax, which you have to check for ORACLE compatibility or some of the old Sybase outer-joins *= or =*.

What you want is a list containing the filename, the name of the function or subroutine and the interesting line of code.

With PowerShell it is rather easy. You start with my Get-VBProject which extracts the files, which contain program code.

VB 6 uses _ at the end of a lines to continue logical lines. I use Get-VBlines to split a VB source code file into logical lines.

Next I transform the text into a stream of objects, representing either a declaration, a property get/set, a function or a modue, with attributes for name of object, filename, position within the file and the coressponding lines of code.

With Select-VBCode_String I can filter objects whoses codelines match artificial patterns.

Adding a little Select-Object and Format-List or Format-Table I get all the answers I need.

It is a nice feature of PowerShell that the streams of objects combine seamless.
Scaning a single file is almost the same as scanning a whole project.

And now the Code:

download | new post

Keine Kommentare:

Kommentar veröffentlichen