OML for the complete beginner, Lesson 12, part 3

Dialog Boxes, concluded <

Since it may be easier to understand all of this by seeing these commands in their proper context, here is a macro that creates and handles a sample dialog box.

  Sub Main
  StartDialog:
    Begin Dialog GetInfo 130, 60, "Name Request"
      Text 4, 4, 84, 12, "Please enter a name:"
      TextBox 4, 20, 45, 12, .UserName
      OKButton 4, 34, 40, 20
      CancelButton 45, 34, 40, 20
      PushButton 86, 34, 40, 20, "Reset"
      OptionGroup .NameOrder
        OptionButton 86, 4, 42, 12, "First Last"
        OptionButton 86, 16, 42, 12, "Last, First"
    End Dialog
    Dim NameInfo As GetInfo
    z = Dialog(NameInfo)

    If z = -1 Then
      Goto Done
    ElseIf z = 1 Then
      Goto StartDialog
    Else
      If NameInfo.UserName = "" Then
        MsgBox "'Name' is a required field."
        Goto StartDialog
      End If
    End If

    If NameInfo.NameOrder = 0 Then
      MsgBox "The name you typed was:" & NameInfo.NameOrder
    Else
      LastName$ = Trim(GetField(a$, 1, ","))
      FirstName$ = Trim(GetField, a$, 2, ","))
      MsgBox "The name you typed was:" & FirstName$ & " " & LastName$
    End If

  Done:
  End Sub

As you can see, right away the total size of the window is established, as is the title of the window. Since there are only two numbers included, the window will be automatically centered on the screen. Then comes a Text command, which simply writes the indicated text in the window you've created (in this case, instructions for what to type in the box), and a TextBox command, in which the user can type some data. After that are three button commands: an OK button, a Cancel button, and a custom button called "Reset". The last statements before the "End Dialog" are an OptionGroup that creates two radio buttons that will dictate how the macro handles the data the user enters.

The command "z = Dialog(NameInfo)" displays the dialog window on the screen, and then waits for one of the three buttons to be clicked. Once that happens, an If...Then statement block routes the program flow appropriately, depending on which button was clicked. Assuming the user typed in data and clicked the OK button, a second If...Then statement block manipulates the entered name--if necessary, as determined by the radio buttons--so that it is in the order "first-name last-name", and displays the name in a MsgBox.


Users of a dialog box which utilizes several of the above commands will be happy to note that it is possible to jump from any control to the next one by using the Tab key, and from any control to the previous one by using the Shift-Tab key combination. This can aid users who get confused when using a mouse or who often accidentally miss a control, as repeatedly pressing Tab or Shift-Tab will cycle through all of the controls, making each "active" in turn.

And that's that. The end...?


Return to part 2.
Return to Main page.

Copyright 2003, Joel A. Hahn
Sponsored and endorsed by OCLC Online Computer Library Center, Inc.