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

Creating a VARPG Appointment Calendar

by Shannon O'Donnell

If you've been faithfully reading my series of articles on using VisualAge for RPG, you're probably becoming pretty proficient at creating simple VARPG apps. Creating simple VARPG applications is fun, and, in fact, it's critical that you learn the basics before you move on to more complex topics. But at some point, you have to move on. You'll do that today as you learn how to use VARPG to create a basic VARPG appointment calendar application.

The application we'll create in this issue will be a basic appointment calendar utility that you can then build on and expand to create your own useful and functional tool. Our sample application will be very basic in function, but it will teach you a few of the basic techniques you'll need to know in order to build your own feature-rich utility.

Appointment Calendar

An appointment calendar application is one in which a user can display a calendar, select a date or dates, add appointment information to those dates, and then redisplay the appointment at some point in the future. Pretty basic. We're going to create such a tool by using VARPG and the power of the calendar part.

Our basic application will allow the user to display a calendar on a GUI panel. The user can add text (appointment information) to a selected date on the calendar and then retrieve that appointment information by double-clicking a selected date. In addition, the user will be able to scroll through the various months on the calendar at will.

We are going to use only three of the calendar part's properties for this sample application: DateText, Date, and DateIDX.

DateText is the property that holds the text the user or application adds to the selected date. It is, in other words, the appointment information the user enters into the Data Entry field.

Date is the currently selected date (day, month, year).

DateIDX is the special property used to set the calendar to the date selected by the user so that when we add or remove appointment information to and from it, we are working with the currently selected date.

Creating the Appointment Calendar Application

If you haven't done so already, create a new VARPG project. Add the following parts and events to the project:

  • Create a new Window Part (if not already displayed):
    Name='WIN1'; Label='Calendar Demo'
  • Push Button Part:
    Name = 'PSBExit'; Label = 'Exit'; Event='Press';
  • Push Button Part:
    Name = 'PSBAdd'; Label = 'Add to Schedule'; Event='Press';
  • Data Entry Field Part:
    Name = 'Dtext';
  • Static Text Part:
    Label = 'Appointment Info';
  • Calendar Part:
    Name='CAL1';
  • When you're all done adding parts, your GUI should look similar to that shown here:

    Name the Calendar Part CAL1.

    Here's what your GUI should look like:

    (Make sure you stretch out the window and calendar parts to be as large as possible so that when the user adds appointment information, it will show up well on the date it was added to.)

    For the calendar part, you want to ensure that the user can see the appointment information on the date he added it to. To allow that, you'll need to make sure that the Show user text property is selected. You can do this programmatically in the code by using the %SETATR built-in function along with the ShowText property, or you can set this property to be checked when you first create the program by selecting the Show user text property in the Style tab of the Calendar Part Properties panel:

    Finally, you need to select the DBLCLICK event for the calendar part:

    Adding Code

    You'll need to set on the Last Record (*INLR) indicator behind the PSBExit push button's PRESS event, just like we've done in all of our previous examples in the last couple of VARPG articles.

    For the PSBADD button, you'll need to add the following code to that button's PRESS event:

        *
      C                   Exsr      GetDate
      C                   Exsr      SetDate
       *
      C                   Eval      %Setatr('WIN1':'CAL1':'DateText') =
      C                               %Getatr('WIN1':'DTEXT':'Text')
       * reset the text field
      C                   Eval      %Setatr('WIN1':'DTEXT':'Text')=*Blanks
    

    This code will execute two subroutines: GetDate and SetDate. One retrieves the currently selected date, and the other sets the currently selected date. We need to retrieve the currently selected date so that we know what date the user selected, and then we'll use that information to set the date index in the program to the correct date, so we can add the appointment information to that date.

    We'll set the user-entered appointment information on the date using the DateText property of the calendar part.

    Add the following two subroutines and D-spec to your VARPG application. The best spot to add it would be immediately following the last D-spec in your code:

      DCNYYMMDD         S              8A
       *********************************************************************
       *
       * Gets the Date selected by the user
       *
       *********************************************************************
      C     GetDate       BEGSR
       *
      C                         Eval      CNYYMMDD = %Getatr('WIN1':'CAL1':
      C                                           'Date')
       * 
      C                        ENDSR
    
       *********************************************************************
       *
       * Sets the index for the day month year selected by user
       *
       *********************************************************************
      C     SetDate       BEGSR
       *
      C                        Eval      %setatr('WIN1':'CAL1':
      C                                         'DateIDX') = CNYYMMDD
       *
      C                      ENDSR
    

    For the DBLCLICK event of the calendar part, you'll need to add code that retrieves the current date selected by the user and then displays that text in the Data Entry part's text field. To accomplish this, add the following code to the DBLCLICK event of the calendar part:

      C     CAL1          BEGACT    DBLCLICK      WIN1
       *
      C                        Exsr      GetDate
      C                        Exsr      SetDate
       *
       * Retrieve the text stored on that date
      C                       Eval      %Setatr('WIN1':'DText':'Text') =
      C                                     %Getatr('WIN1':'CAL1':'DateText')
       *  
      C                      ENDACT
    

    Take It for a Test Drive!

    That's all you need to do to create your initial appointment calendar application. You're now ready to compile the application and take it for a spin. If you're not sure how to compile and run the VARPG application, go back and read the first article in this series.

    Select a date from your calendar and then type some text into the Appointment Information text field. Click the Add to Schedule button to add that appointment information to your calendar. Notice that the appointment information now appears on the date you selected. Now add appointment information to some other dates. Go back and double-click a previously selected date (that already has appointment information on it). Notice that the appointment information is now displayed in the Data Entry field, where you can change it.

    Now that you understand the basics of working with the calendar part in VARPG, it's time you expand on this initial appointment calendar application. Add some logic so that, if a date has an appointment on it, and it's also the current date, the background color of that date is set to the color red. Or perhaps you might make a selected date change its outline, to be highlighted, if an appointment is made for the current date. Or perhaps you'll display a pop-up window of the appointment information for the user, if the appointment is for the current date. Be creative! Experiment! And most of all, have fun!

    Sponsored By
    SOFTLANDING SYSTEMS

    DOWNLOAD FREE WEBSPHERE TOOLKIT!

    Automate WebSphere management tasks on the iSeries with commands that stop/start a WAS instance, pre-compile JSPs in production before users access them, copy configs for editing, backup, or applying to another server, and more.

    If your WebSphere environment includes the iSeries, these tools and other solutions from SoftLanding Systems will give you a head start on managing your WebSphere applications.

    TurnOver Change Management oversees the entire development process from request thru deployment to any server -- iSeries, NT, Unix, or Linux. Automate WebSphere Application Server tasks within TurnOver with the FREE WebSphere toolkit.

    PVCS Version Manager plugs into both the WebSphere IDE and TurnOver to deliver the most streamlined, integrated management of WebSphere and iSeries objects available today.

    TurnOver PDQ almost entirely eliminates downtime during database changes or reorgs.

    SoftLanding brings you a powerful combination of WebSphere-integrated software to streamline and automate your entire WebSphere development process.

    Get your free WebSphere tools and more info/free product trials online, or call SoftLanding at 603-924-8818 x1.

    THIS ISSUE
    SPONSORED BY:
    SoftLanding Systems
    LANSA
    ACOM Solutions
    ASNA
    Profound Logic Software
    WorksRight Software
    BACK ISSUES
    TABLE OF CONTENTS
    Creating a VARPG Appointment Calendar
    Dynamic Selection with Embedded SQL
    Validating XML with a Document Type Definition
    The Ins and Outs of Qshell
    The iSeries Toolbox for Java: GUI-izing Program Calls
    Exploring iSeries Navigator Application Administration
      Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
      Last Updated: 5/8/02
    Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.