OML for the complete beginner, #12, part 1

Dialog Boxes

Now that you've had the opportunity to use the InputBox command on occasion, have you ever looked at the screen display of an InputBox and wished you could change the size of the window, the location of the window, the location of the buttons inside the window, the size and number of the data entry fields, and so forth? Or just wished you could design an input window so that users could type in information and the macro could then use and play with what was typed in? There is a way to do this using dialog boxes--but be warned, the concepts are easy but the actual implementation can be extremely intimidating and aggravating.

(This is not always the case with certain other Visual Basic-based macro languages, as other macro editors often include the ability to change the size and contents of a window using mouse and menus, while the computer takes care of figuring out the programming commands needed to achieve the look you want. You may find it easier--if you have access to one of those other programs--to create a dialog box using that program, then copy it over into the PfW macro editor and make the few changes necessary to make the resulting commands compatible with OML.)

Here is the program code for a sample dialog box along the lines of what is used by the InputBox command. Note that this is completely non-functional as is, in order to better explain the various parts. Elements in angle brackets represent strings that can be included as a string or as plain text in quotation marks; square brackets designate optional elements.

  Begin Dialog <name> [x, y,] dx, dy, [<caption>]
    Text x, y, dx, dy, <text>
    TextBox x, y, dx, dy, .<func1>
    OkButton x, y, dx, dy
    CancelButton x, y, dx, dy
  End Dialog
  Dim <name2> As <name>
  [Dialog <name2>]  [z = Dialog(<name2>)]

As you can see by comparing the first line to the second to last line, the <name> of the dialog is used later on to define the way the elements in the dialog box are referenced by the rest of the macro.

The <caption> is the title (if any) you want to appear in the blue bar at the top of the window; if this is left out, the default is "Softbridge Basic Language", as you've probably seen on message boxes.

X = across, y = down. X = 1 is 1/4 the average width of a letter; since the font used does not have uniform-width letters, x = 2 is roughly the width of the letter "i", and x = 6 is roughly the width of the letter "m". Y = 1 is 1/8 of the height of a normal capital letter; y = 12 will give enough room to display the entirety of any capital letter or a letter with a tail. Dx and dy are the total width and height of the box/window being defined. In the Begin Dialog statement, x and y are optional; they define where on the screen to place the box. If they are left out, the default is a central location.

<Name2> is defined to be the results of dialog <name>; because of this, <name2>, rather than <name>, is used by the rest of the macro to refer to the various elements of the dialog box. That is, <name2>.<func1> (for example, SampleDialog.Button1) is a variable containing whatever was typed in the textbox.

For the Dialog statement, one or the other form must be used, but not both at the same time, as here. The latter method works best if the only controls you have in the box are buttons; it equates to -1 if the Ok button is pressed, 0 if the Cancel button is pressed, and 1 and higher for any user-defined buttons, in the order of the Buttons commands in the macro. The former method seems to work best when there are a lot of boxes rather than buttons. However, it requires the use of an error handling routine if you want to continue or don't want an error box to pop up, as pressing the Cancel button causes in the macro to generate a "Command failed" error.


Continue on to part 2 of the lesson...
Return to Lesson #11.
Return to Main page.