|
Fun with VARPG Radio Buttons
by Shannon O'Donnell
In the last issue, I introduced you to the integrated development environment of IBM's VisualAge for RPG by showing you how to add a couple of
buttons to a GUI Form and then display some text in a form's static text part. In this issue, I'm going to
show you one way you might expand on the idea of adding text, by using radio button parts to control what
text appears on the Form.
If you have not yet worked your way through the example VARPG application I showed you in "VisualAge for RPG:
Who Knew It Was So Much Fun?" then you should do so before continuing with this article. I'm not
going to review everything I discussed in that article, so you may need to review it in order to understand
some of the basics mentioned here.
In the last article, you saw how easy it was to display some text on a VARPG GUI when the user clicked a
Push Button part. This time, let's offer the users the choice of what text they want to display. One way we
can do that--although certainly not the only way--is with radio buttons.
Radio Buttons
Radio buttons are used in almost every development environment, except for the RPG-DDS environment.
Radio buttons are used extensively in Java, HTML, C++, Visual Basic, and, in fact, every other
language/environment on the planet. In RPG-DDS, I guess the best equivalent would be a one-character
input field.
Radio buttons are typically used to allow users to make a single choice from a group of choices. For
example, you might want a user to indicate that he like eggs but not potatoes. If you needed to allow a user
to make multiple choices from a category, you'd use a check box (regardless of the language, it's almost
always called a check box).
In this article, you'll see how to use the radio button to allow users to choose what text they want to display
on a GUI.
Adding the Parts
Since you've already read the last article on VARPG, I'll skip telling you what the parts are and how to find
them. Also, I won't cover the concept of "events" or how to trap events. If you're not sure what any of this
means, please go back and read the last article again.
What we will do in this example is add an empty static text part and three radio button parts to the VARPG
GUI, and then add some text to the labels of each of the radio buttons. When the user clicks a radio button,
to select it, we'll retrieve the radio button's label, using the %GETATR built-in function, and add the text of
that label to the label of the static text field, using the %SETATR built-in function. The result will be that
any label associated with the radio button that the user clicks will now be displayed in the static text field of
the VARPG GUI.
Detailed Instructions
Here are the steps for creating a user-directed text display GUI using radio buttons:
- Start a new VARPG GUI project.
- Change the window part name to "WIN1".
- Change the window title to "VARPG Radio Button Demo".
- Add a push button part.
- Change the push button part name to "PSBEXIT".
- Select the "PRESS" event.
- Add the code to this "PRESS" event to "set on" the last record indicator.
- Add a static text field to the GUI form.
- Change the part name of the static text field to "TEXT1".
- Add a radio button part to the GUI form.
- Change the part name of the radio button to "RD1".
- Change the label of the radio button to "Unix Stinks!"
- Add a second radio button part to the GUI form.
- Change the part name of the radio button to "RD2".
- Change the label of the radio button to "Windows Crashes!"
- Add a third radio button part to the GUI form.
- Change the part name of the radio button to "RD3".
- Change the label of the radio button to "iSeries RULES!"
Once you have completed these steps, you will see something like this:
Select the first radio button's "SELECT" event. (In the example, the third radio button is shown, but you’ll
want to select the first radio button first.)
Add the following code to the SELECT event for the first radio button:
Select the second radio button's "SELECT" event.
Add the same code to this SELECT event that you added to the first radio button's SELECT event. Make
sure you change the name of the radio button in the code from "RD1" to "RD2"!
Select the third radio button's "SELECT" event. Then add the following code to the SELECT event for the
third radio button:
Notice that, in addition to the code we added in the previous examples, we've also added code here to
change the font name and the font size of the text that gets displayed. I did this to show you how you can
access other properties of the static text font. I also wanted to make the phrase "iSeries Rules!" really stand
out for the user. You will probably want to add similar code to the other radio buttons' SELECT events so
that you can reset the font size back to normal when those buttons are selected.
When you're all done, save your project and build a new Windows version of it. And then run it. Click the
various radio buttons to see what happens.
Oh, What Fun It Is to Code and Click on a GUI All Day
This example, like the one in the last issue, was fairly simple. But you must learn to walk before you can
run! It's important that you get familiar with GUI and event driven programming before you start delving
into more complex topics such as writing to database files or interacting with native ActiveX objects. Be
patient. Eventually, we'll cover all of those topics!
|