You may have noticed that when you execute the Hello application and click on the Hello push button, the text string in text box control changes from "Begin" to "Hello!" as expected.
However, if you click on the Hello button again, nothing seems to happen. Actually, something is happening - the value of the text string is being set to "Hello!" - it's just that it is constantly being set to the same value each time so you don't see any visual effect on the desktop.
You will now alter this behavior to toggle the text value each time a user clicks on the Hello push button.
You do this by adding additional program code to the event procedure for the Hello push button (remember that "CmCommand1" is the actual PowerCOBOL control name for the one and only push button you have created, while its text value is Hello).
To add COBOL code for the desired behavior, move the mouse over the CmCommand1[PcobCommandButton] push button control and right-click once to display a pop-up menu.
Move the mouse to Edit Event Procedure on the pop-up menu to display a secondary pop-up menu. Now move the mouse to the *Click event and left-click once on it. (The '*' in front of the event name indicates that you have previously created custom procedure code for this event).
An even simpler way to edit an existing COBOL scriptlet is to simply move the mouse over it in the Project Manager window, right click on it and left click on Edit in the context menu that appears.
This will display the PowerCOBOL Editor containing the procedural code you created earlier:
You will now add additional code to this event procedure. The behavior you want to achieve is to toggle the text value in the text box control each time the user clicks on the Hello push button.
In order to achieve this behavior, you will need to define a data item to contain the current state of the text box, and add some procedural code to implement the desired behavior to toggle the text value.
Because you are dealing with COBOL, this is relatively straightforward. Modify the event code so that the event procedure in the CmCommand1 Click event window appears as follows:
Save the code and close the Editor window by clicking on the close (X) button in the upper right corner of the window.
Now save your project work by selecting Save in the File Menu.
You are now ready to try out your new enhancements. Move the mouse over the Hello[Project] control and right-click once to display a pop-up menu.
Now select Rebuild All. Your program will be recompiled and re-linked into an executable file. If you encounter any errors, carefully retrace the steps above.
You are now ready to run the enhanced Hello application. Move the mouse over the Hello[Module] control and right-click once on it to display a pop-up menu. Now select Execute.
The Hello application will appear on your desktop. The new font size and color scheme should be apparent in the text control. When you click on the Hello push button, you should experience the new behavior from the toggle code you placed in the application.
You may, however, notice a new problem. The actual text control may be too small to display the larger font size you selected, and may chop it off.
If this is the case, you need to enlarge the size of the text control area (CmStatic1).
You could accomplish this by modifying the Height and Width properties of the CmStatic1 control in the right windowpane. Chances are, however, that you would not know the precise numbers to place in the Height and Width properties.
It is a better bet that you could more easily select the correct size by actually viewing and enlarging the text control in the form edit mode.
Close the application by selecting the close (X) button in the upper right corner of the window. Go back into the Form Editor by moving the mouse over the Hello[Form] control and right clicking on it to display a pop-up menu. Click on Open.
This will display the Hello application form (window) in the Form Editor.
Left-click once on the CmStatic1 StaticText control to select it (you should notice a series of small square dots outlining this text box). Now simply select one of the horizontal sides by clicking and holding the left mouse button down and dragging it outwards. Now do the same for one of the vertical sides.
Drag the sides until you are convinced the text box is large enough to hold the "Try it Again" text string.
Now close the Form Editor by selecting Exit from the File menu or by clicking on the close icon (X) in the upper right corner. Notice you don't have to save the form before exiting the Form Editor.
Now save your project and rebuild it. Execute it to convince yourself you have corrected the problem.
When you have finished experimenting with this new version of the Hello application, quit the application by clicking on the close (X) button in the upper right corner of the window.