Freigeben über


The Art of Debugging – A Developer’s Best Friend – Lesson 13 – Debugging VBScript – Repost

Code used in demo:

 

    1: dim filesys
    2: dim step_number
    3: dim trg, src
    4:  
    5: step_number = "04"
    6:  
    7: set filesys=CreateObject("Scripting.FileSystemObject")
    8:  
    9:  
   10:  
   11: src = "c:\devprojects\azure\labs\BuildingWindowsAzureServices"
   12: trg = "C:\livedemos\Azure\HelloWorld\step" & step_number
   13: If filesys.FolderExists(trg) Then
   14:    filesys.DeleteFolder trg, true
   15: end if
   16: call Generatepath(trg)
   17: wscript.echo "Copying " & src & "...."
   18: 'filesys.CopyFolder src, filesys.GetParentFolderName(trg) & "\"
   19: filesys.CopyFolder src, trg & "\"
   20:  
   21:  
   22: Function GeneratePath(pFolderPath)
   23:     GeneratePath = False
   24:     If Not filesys.FolderExists(pFolderPath) Then
   25:         If GeneratePath(filesys.GetParentFolderName(pFolderPath)) Then
   26:             GeneratePath = True
   27:             Call filesys.CreateFolder(pFolderPath)
   28:         End If
   29:     Else
   30:         GeneratePath = True
   31:     End If
   32: End Function

 

Debugging VBScript is incredibly easy.  This will no doubt be the most straightforward and simplest way to debug code of all the previous blogs.

I recommend by starting with an administrator level command prompt.  If you are a developer and not an end user, running as an administrator is recommended for most operations.

One of my favorite editors is VI.  Below you can see a bunch of VBScript code that we wish to debug one line at a time.

To make my life easier I will navigate to the c:\livedemos\q3fy09\draft\azure folder and execute the VBScript below using a debugger.

clip_image002

You can begin this lesson by starting a command prompt as administrator.

clip_image004

Notice my command prompt window below.  Also notice my VBScript file waiting there to be executed.  Let’s go ahead and run that script in the debugger.

If you ever forget the syntax, you can just execute cscript /?.

clip_image006

Cid added the secret to debugging.cscr using our example simply type in cscript /x /d MakeSteps.vbs

clip_image008

Here is the results of our command.

clip_image010

clip_image012

Select a new instance of Visual Studio.

clip_image014

Simply use the debugger commands previously described in the blogs.

clip_image016