Because you want the form to include buttons or options that users can select, you want the script to pause execution until the script retrieves the results of any choices the user made on the form. To pause the script execution, you need to move onto a slightly more complex script that will form the basis of any form creation you do with GooeyScript.
Creating a basic working form. Listing 3 shows BasicWorkingForm.vbs, which lets you create a single-button form. After the form appears on screen, the script pauses until the user clicks the form button. Then, the script continues to execute, the form unloads gracefully, and the script ends.
First, you need to instantiate the GooeyScript::Form object for your form just as before, using the WScript::CreateObject method and placing that object into the gsForm variable. This method call differs from the Listing 1 method call, however, because you need to extend the WScript::CreateObject method and use a second parameter. A key part of the Listing 3 method call is creating an event handler that can respond to events that the form fires at the event handler. To accommodate these events, you need to pass a second parameter to the script, which consists of a string of text characters ending in an underscore (_).
Set gsForm = _ WScript.CreateObject _
("GooeyScript.Form", "gsForm_")
By trapping events, you can create subprocedures such as gsForm_ComboBoxClick and gsForm_ButtonClick to respond to GooeyScript events.
After you load the form, you can use the Button::Load method to add the button to the form as follows:
gsForm.Button.Load "ButtonExit", _
175,75,180,125,"Exit the form", TRUE
This method creates a button (with the object name ButtonExit) that says Exit the form. The button, which is 180 pixels wide and 125 pixels high, appears 175 pixels from the left edge of the form and 75 pixels from the top. The last parameter makes the button visible when the form is on screen. When a user clicks the button, the script passes the object name to the event handler to identify which button the user clicked. Because this form has only one button, you don't have to worry about which button the user clicked. However, if the form had multiple buttons, identifying which button the user clicked would be crucial.
Next, you can make the form visible and use GooeyScript's Form::Pause method to halt execution of the script until an event calls the Form::UnPause method. At this point in the script, you define an event handler to trap the Form::ButtonClick event that GooeyScript sends. Although this event takes a parameter (i.e., the button name), you don't use it in the script. When a user clicks the button, the event handler simply calls the Form::UnPause method so that the main body of the script can continue to execute. The subprocedure that calls Form::UnPause is
Sub gsForm_ButtonClick _
(strButtonName)
gsForm.UnPause
End Sub
After the script calls the Form::Pause method, you insert the remaining commands (e.g., Form::Unload) that must execute to close the script and remove all instances of the GooeyScript form objects.
Expanding on GooeyScript
You now know how to use GooeyScript's basic features to easily create forms. In my next column, I'll describe how you can use GooeyScript to create other useful components such as custom backgrounds and progress bars and introduce you to another useful ActiveX control.