This column is the third in a series to show you how to use Windows Script Components (WSC) to create a progress bar dialog box you can use with your scripts. Figure 1, page 10, shows an example of what this dialog box looks like. Previously, I discussed the various XML elements in a .wsc file and to create a ProgressDialogBox object and its methods and properties. (The first two articles in the series were "Scripting Solutions with WSH and COM: Using WSC to Build a Progress Bar Dialog Box, Part 1," September 2000, and "Scripting Solutions with WSH and COM: Using WSC to Build a Progress Bar Dialog Box, Part 2," October 2000.)
With the rudiments of the .wsc file in place, you now need to create three items to finish the WSC project. First, you need to create an HTML template that the .wsc file will use. Although you can embed the HTML template in the .wsc file, the template is much easier to understand if it's a separate .htm file. Second, you need to create the WSC functions in the .wsc file. Finally, you need to create a calling script. This script calls the .wsc file and uses an instance of the file's ProgressDialogBox object to create a progress bar dialog box. This month, I discuss the HTML template; next month, I'll discuss the WSC functions and the calling script.
Creating the Template
The .wsc file uses the HTML template in Figure 2 to create a progress bar dialog box. Listing 1 contains the source code (progress.htm) for that template. (You can find progress.htm in the Code Library on the Windows Scripting Solutions Web site at http://www.winscriptingsolutions.com.) Understanding the source code is easier if you break the file into its main components: the title (X in Figure 2), the progress statements (Y and Z in Figure 2), the progress bar (the bar under X in Figure 2), and the Cancel button.
The code at callout A in Listing 1 provides the dialog box's title. The title is a text string in style H3 (i.e., Heading 3). In this template, the letter X serves as a placeholder for the text string. You later use the calling script to specify the title. For example, the calling script I'll discuss next month, wshProgDialogDemo.vbs, gives the progress bar dialog box the title that Figure 1 shows.
To identify the title, I have given it the unique ID of ProgressBarTitle. Similarly, as callout D in Listing 1 shows, I have given the two progress statements the unique IDs of ProgressBarLine1 and ProgressBarLine2. ProgressBarLine1 and ProgressBarLine2 are two text strings in style H4 (i.e., Heading 4). The letters Y and Z, respectively, serve as placeholders for these text strings.
You can easily customize the format or style of the title and progress statements. For example, you can increase the title's size by changing H3 to H2 in the code at callout A. However, you can't change the three unique IDs because the WSC functions in the .wsc file reference these IDs.
The code at callout B in Listing 1 draws the text box that appears under the letter X in Figure 2. This text box, which has the unique ID of ProgressBar, displays the data in the Value property in the Wingdings font. In other words, the progress bar displays whatever you set the Value property to. You set this value to a series of block characters to indicate progress—and the easiest-to-read block character is *, which is the letter n in the Wingdings font.
The code at callout C in Listing 1 places a Cancel button in the dialog box. When users click Cancel, it prompts the .wsc file to fire a cancel event, which in turn, triggers the calling script to take the appropriate action. I'll cover the actions that the calling script takes next month. Right now, you just need to make sure that the .htm file tells the .wsc file to fire the cancel event when users click Cancel.
The code at callout C accomplishes this task by first creating a hidden form, which has a string variable called strHiddenValue. The code initially sets this variable's value to an empty string. Next, the code creates a subprocedure called SetAlertThatCancelHasBeenPressed. When users click Cancel, this subprocedure sets strHiddenValue to "cancel". In the .wsc file, a WSC function called PercentComplete regularly checks the value in strHiddenValue. When the value is "cancel", the WSC function fires off the cancel event.
Next month, I'll show you how PercentComplete and the other functions in the WSC work. In addition, I'll discuss the sample calling script wshProgDialogDemo.vbs.