Guild Companies, Inc.  
 
Midrange Programmer - How-To Advice & Free Code
OS/400 Edition
Volume 1, Number 8 - April 25, 2002

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:

  1. Start a new VARPG GUI project.

  1. Change the window part name to "WIN1".

  1. Change the window title to "VARPG Radio Button Demo".

  1. Add a push button part.

  1. Change the push button part name to "PSBEXIT".

  1. Select the "PRESS" event.

  1. Add the code to this "PRESS" event to "set on" the last record indicator.

  1. Add a static text field to the GUI form.

  1. Change the part name of the static text field to "TEXT1".

  1. Add a radio button part to the GUI form.

  1. Change the part name of the radio button to "RD1".

  1. Change the label of the radio button to "Unix Stinks!"

  1. Add a second radio button part to the GUI form.

  1. Change the part name of the radio button to "RD2".

  1. Change the label of the radio button to "Windows Crashes!"

  1. Add a third radio button part to the GUI form.

  1. Change the part name of the radio button to "RD3".

  1. 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!

Sponsored By
BCD INT'L

WebSmart -- Superior Technology to create your OWN solutions

iSeries News Editors Choice Finalist, & 2001 PEA Winner Best e-Business/
e-Commerce Development tool.

Extend AS/400 apps and use existing skills. -- You'll be stunned at how fast, easy & affordable developing robust, elegant & secure Intranet/Internet and browser based applications can be!

Try the #1 Web tool for FREE.

Click www.BCDsoftware.com or call us at 630-986-0800.

THIS ISSUE
SPONSORED BY:
ASNA
BCD Int'l
Tramenco
Aldon Computer Group
Profound Logic Software
WorksRight Software
BACK ISSUES
TABLE OF CONTENTS
Empower Users with Embedded SQL
Fun with VARPG Radio Buttons
Simplify JSP Applications with JavaBeans, Part 2
Stream I/O in Qshell
The iSeries Toolbox for Java Does Service Programs
Learning Java by Example
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 4/24/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.