3.2 Adding an Action Subroutine for OK

Let's create an action subroutine for the OK push button. This action changes the color of the entry field when it is selected during program execution. If the current background color is not red, it changes to red when it is selected. If the entry field button is already red, it changes to gray when it is selected.

The ability to change colors many not seem useful, but it gives you an opportunity to experiment with the new operation codes. Later we will add some more logic to the PRESS event for this push button. Let's add the logic for the OK push button.

Follow these steps:

  1. Select the OK push button part with the left mouse button. Click the right mouse button to view the pop-up menu for this part.
  2. Select Events and then select PRESS from the Events submenu. The VisualAge RPG Editor window appears.
  3. If you want to get information about the background color of the entry field, use the GETATR operation code. The following logic sets the background color to red if it is not the current background color. Otherwise, it sets the color to gray. Enter this logic between the BEGACT and ENDACT lines.
  4. Use the Editor to insert six blank lines between the BEGACT and ENDACT lines. Move the cursor to this line in the source and press F4(Prompt). Select the C-Calculation radio button. Click OK. Remember to change the type of specification as required.

    
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
     *
    C     'CUSTNO'      Getatr    'BackColor'   BCOLOR            2 0
    C                   If        BCOLOR <> *RED
    C     'CUSTNO'      Setatr    *RED          'BackColor'
    C                   Else
    C     'CUSTNO'      Setatr    *PALEGRAY     'BackColor'
    C                   EndIf
    
  5. To save this change, choose the File option from the menu bar, and then select the Save choice.
  6. Close the editor by double-clicking the left mouse button on the top left-hand corner of the editor window.
  7. Click on to indicate that you've done all the steps.