Write the script to open the window

Where you are

   Create a new window

   Add controls to the window

   Change the tab order on the window

   Code some Help events and preview the window

>   Write the script to open the window

Now you add a one-line script to open the login window as soon as the application starts executing. Although you could change the script in the Application object Open event to open the login window, in this tutorial you make the call to open the login window from the Open event of the MDI frame window. This window (w_pbtutor_frame) was created by the Template Application wizard.

In wizard-generated script, the frame window is called by the Application object Open event. When you add a call to open the login window from the MDI frame window Open event, the login window still displays before the frame window. Because the login window is a response window, it temporarily blocks execution of the remainder of the frame window Open event script.

In this exercise you:

Modify the frame window Open event

Now you modify the frame window Open event script to open the login window.

Wizard-generated script

The frame window Open event already has a script associated with it that was generated by the Template Application wizard. The script creates an instance of a wizard-generated user object that serves as a sheet (window) manager. The Open script then calls the ue_postopen event.

The ue_postopen event registers sheet windows with the sheet manager. The event is posted to the end of the messaging queue for the window and is not processed until the remainder of the Open script (that you add in this lesson) is executed.

  1. Select File>Open from the menu bar.

    Make or verify the following selections in the Open dialog box:

    Open dialog box item

    Selection to make (or verify)


    pbtutor -- currently your only target


    pbtutor.pbl -- currently your only library; if you cannot see the full library name, you can drag the edge of the dialog box to increase its size

    Object Name


    Objects of Type

    Windows -- you must make sure this is selected before you can select a named object of this type



    The w_pbtutor_frame object is the main application window created by the Template Application wizard.

  2. Click OK.

    The Window painter opens and displays views of the main application window in the painter workspace.

    If the Script view is not open, you can open it by selecting View>Script in the workspace menu bar or by double-clicking inside the Layout view.

  3. Move the cursor to the top of the Script view.

    The view title bar rolls down. It contains a pushpin button on the left and a maximize/minimize button and a close button on the right.

  4. Click the pushpin in the title bar of the Script view.

    The title bar of the Script view reads:

    Script - open for w_pbtutor_frame returns long
  5. Make sure the Open event displays in the Script view.

    The PowerScript code in the Script view is preceded by comments.

    Using comments

    A comment in PowerScript is indicated by either two forward slashes (//) at the start of a single-line comment, or a slash and an asterisk (/*) at the start and an asterisk and a slash (*/) at the end of a single-line or multiline comment. Comments are not parsed by the script compiler.

    You now modify the Open event script to cause the login window to display.

  6. Click after the parentheses in the line that reads:

    this.Post Event ue_postopen ( )

    The ue_postopen event does not take any arguments.

  7. Press Enter twice.

    This adds a blank line in the Script view for legibility. The cursor moves to a new line following the blank line.

  8. Type Open the login window on the new line in the Script view.

  9. Click the Comment button () in PainterBar2.

    Two slashes appear in front of the line you typed -- it is changed into a comment.

  10. Move the cursor to the end of the comment.

    Press Enter to add a new line.

    Type open (w_welcome) on the new line.

    This calls the Open function to display the login window you created.

Accessing context-sensitive Help

To access context-sensitive Help for a function or reserved word (such as Open), select the function or reserved word in the Script view and press Shift+F1. You can always open the main Help screen by pressing F1.

Compile the script

Now you compile the script you just typed. In this exercise, you use a pop-up menu item to compile the script. PowerBuilder also compiles a script when you close the Script view or when you select a different object, event, or function for display in the Script view.

Handling errors in scripts

When there is an error in a script, an error window displays at the bottom of the Script view with the line number of the error and the error message.

To find an error

Click on an error message to move the cursor to the line that contains that error. After you correct the error, you can try to compile the script again.

Commenting out errors

PowerBuilder does not save scripts that have errors. If you want to save a script that has errors, select the entire script and click the Comment button to comment out the code. You can come back later, uncomment the code, and fix the problem.

  1. Right-click anywhere in the Script view script area.

    Select Compile from the pop-up menu.

    The script compiles. You do not leave the Script view or the Window painter workspace.

  2. Select File>Save from the menu bar.

    Select File>Close from the menu bar.

    The Window painter closes.