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:
- Define the message text and
message box style with D specifications in your RPG source.
- 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:
- Select Project > Define
messages from the menu bar.
- In the Define Messages - VisualAge
RPG window click Create. This window display allows you to define a new
message.
- 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.
- Type some message text in the Message
entry box. This is the text that appears on the message box.
- 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.
- Select the push buttons to appear
on the message box from the Buttons drop-down combination box. Click OK.
- Select the Moveable
check box. If this is not checked, you cannot move the message box when it displays.
- Click Save to
save your message definition.
- 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:
- 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.
- Add the following statements after
the WRITE statement to display the message if the record is not found:
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+.
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
C ELSE
C *MSG0001 DSPLY REPLY 9 0
- Save the source in the Editor.
Then build and run the application.
- 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.
- 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.