Make the Wizard Interact with DevStudio

The final goal will be adding a new button to the scriptlet Toolbar to run our wizard, and start editing the file when it has done.

The new macro: RunWizard, will begin asking for the name of the scriptlet.

Sub RunWizard
  s = InputBox( "Type in the name of the scriptlet you want the wizard to generate.", 
                "Scriptlet Wizard", "MyScriptlet" ) 
  ' more code follows

The string returned is passed to the wizard in such a way as to allow it to initialize and disable the name field. In practice, the wizard will only allow you to type in the name of the scriptlet if you don't pass it on the command line.

You cannot specify the argument to pass to any tool using indirection or variable. What we actually need the following:

  1. Get a string through a dialog.

  2. Pass it to the wizard and have it create a file with that name.

  3. Open that file in DevStudio.

Step 1 and Step 3 occur inside Developer Studio. While we can figure out a way to pass data to the wizard, the opposite is not so simple. Again, the ideal solution would be to put it all together in an add-in module.

A rudimentary technique—nevertheless perfectly adequate—for this kind of communication consists of:

  1. Using InputBox to get the desired scriptlet name.

  2. Opening a new HTML document and naming it.

  3. Saving the document in the desired path.

  4. Using a predefined argument (Current Text) to pass the name up to the wizard.

Using InputBox allows us to store the name of the file inside the VBScript code. Then we create a new HTML document, write this name to it and save it to a certain path. Notice that this is now the active document, and our string is the current text.

Furthermore, we need to modify our user-defined tool to get it to accept the current text on the command line. This is accomplished via the pseudo- command $(CurText), as shown in the screenshot below.

Applying this setting will run the wizard, passing the string entered through InputBox as the first command-line argument.

Before launching the wizard, we create a new HTML document with that name. This document will be rewritten by the wizard causing a nice side-effect when the control passes back to the Developer Studio.

By clicking Yes, we have the scriptlet opened and ready for further editing! The whole source code for the macro is as follows:

Sub RunWizard()
   s = InputBox( "Type the name of the scriptlet you want the wizard to generate.", 
                 "Scriptlet Wizard", "MyScriptlet" )
   Set NewDoc = Application.Documents.Add("Text")
   NewDoc.Language = "HTML - IE 3.0"
   NewDoc.Save ,True 
   ActiveDocument.Selection = s
   Application.ExecuteCommand "UserTool7"
End Sub

The Documents.Add method creates and opens a new document window. The type of the document is one of the arguments. We also need to set the Language attribute to enable syntax-highlighting. The next step is saving the document. We avoid indicating a name so that the Developer Studio prompts us with the common Save dialog. This allows us to specify a path. The last step is writing something in the document. We need this in order to pass some data to the wizard. Because of the tool's setting, the wizard will receive the current text; that is the word at the current cursor location.

Do you remember the rightmost button of the scriptlet toolbar we mentioned earlier? Yes, it's a button that executes the RunWizard macro and, therefore, starts the process we discussed above.

© 1997 by Wrox Press. All rights reserved.