5.3 Using Message Boxes

As the application is now, if you enter a customer number that is not in the database, no action is performed, and no message is displayed. You can add logic that causes a message box to display to inform you that the customer number is invalid.

There are two methods to define the message text:

  1. Define the message text and message box style with D specifications in your RPG source.
  2. Define a message in the GUI Designer.

In either case, you use the DSPLY operation code to display the message in a message box.

Let's define a message in the GUI Designer.

Follow these steps:

  1. Select Project > Define messages from the menu bar.
  2. In the Define Messages - VisualAge RPG window click Create. This window display allows you to define a new message.
  3. Scroll through the different types of message that are available and select any one. The message type determines which icon displays on the message box.
  4. Type some message text in the Message entry box. This is the text that appears on the message box.
  5. You may also type some additional message text in the Message Help entry box. This text appears when the Help push button is pressed on the message box.
  6. Select the push buttons to appear on the message box from the Buttons drop-down combination box. Click OK.
  7. Select the Moveable check box. If this is not checked, you cannot move the message box when it displays.
  8. Click Save to save your message definition.
  9. MSG0001 displays in the Define Messages window. VisualAge RPG assigns a message number. You cannot change these message numbers. Click Save to save your message.

Displaying a Message

Now you need to add the code to your action subroutine to display the message you have just created.

Follow these steps:

  1. Add the code to your action subroutine to display the message you created. Open the CUSTINQ window if it is not already open by double-clicking on CUSTINQ in the VisualAge RPG window. Select the PRESS event for the OK push button to edit its action subroutine.
  2. Add the following statements after the WRITE statement to display the message if the record is not found:
  3. 
    *...1....+....2....+....3....+....4....+....5....+....6....+....7....+.
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C                   ELSE
    C     *MSG0001      DSPLY                   REPLY             9 0
    
    
  4. Save the source in the Editor. Then build and run the application.
  5. Enter an invalid customer number such as 9999999. A message box displays with the message text you defined earlier. A Help push button has been added to the message box. This is because you specified second level message text.
  6. Click on the Help push button to see the second level help you typed when you created the message. Close the help. Click on the EXIT to exit the application.

Click on to indicate that you've done all the steps.