GUI ScreenIO for Windows

 ScreenIO.com


How to Use Listbox Controls in Your Program

The definitions for a listbox reside in both the -3 and the -4 portions of the panel copybook.  The list associated with the listbox is in the -3 area, and the selected value (or the value typed in the associated edit control) is in the -4 area.  This makes a listbox very easy to use.

The copybook segments for a listbox are shown below:  Notice the comments explain much of what you need to use it. 

 01 panel-3.
      .
      .
     05  MY-LISTBOX-LISTBOX.
*                         :
*                         : MAX is provided so your program
*                         : can know the maximum number of
*                         : elements in the table.
       10  MY-LISTBOX-MAX          PIC 9(4) COMP-5 VALUE 10.
*                         :
*                         : SELECTORS: Single or Multiple.
*                         : SEL will contain one byte flags
*                         : for each entry in the list which is
*                         : set to 'S' when that list entry is
*                         : selected. You may "suggest" an entry
*                         : by setting this before display.
       10  MY-LISTBOX-SELS VALUE LOW-VALUES.
         15  MY-LISTBOX-SEL OCCURS 10 INDEXED MY-LISTBOX-SDX
                                      PIC X.
           88  MY-LISTBOX-SELECTED    VALUE 'S'.
           88  MY-LISTBOX-NOTSEL      VALUE LOW-VALUE.
*                         :
*                         : This is the table of elements which
*                         : define the entries for this control.
       10  MY-LISTBOX-TBL.
         15  DAT--13-40   PIC X(40) VALUE
                         'Alaska WashingtonOregon Montana'.
         15  DAT--53-60   PIC X(60) VALUE LOW-VALUES.
       10  FILLER REDEFINES MY-LISTBOX-TBL.
         15  MY-LISTBOX-ITM OCCURS 10 INDEXED MY-LISTBOX-IDX.
           20  MY-LISTBOX-VAL   PIC X(10).

 01  panel-4.
       .
       .
     05 MY-LISTBOX        PIC 9(4) VALUE ZERO.
       88 MY-LISTBOX-NONE-SELECTED VALUE ZERO.


You can load data to the list at runtime in a little perform loop, like this. 

If you use the value in MY-LISTBOX-MAX to terminate the perform, your code won't have to be modified if you change the number of elements in the list...

    PERFORM
        VARYING MY-LISTBOX-IDX FROM 1 BY 1
        UNTIL MY-LISTBOX-IDX > MY-LISTBOX-MAX
          .
          .
      MOVE mydata TO MY-LISTBOX-VAL (MY-LISTBOX-IDX)
    END-PERFORM

Clear un-used entries to low-values, not spaces. 

If you want to have an item in the list appear selected when the listbox is activated, just set the selected byte for that item like this:

    SET MY-LISTBOX-SDX TO MY-LISTBOX-IDX
    SET MY-LISTBOX-SELECTED (MY-LISTBOX-SDX) TO TRUE

When GUI ScreenIO returns to your program, it will tell you how many items were selected.  If any were selected, examine the selection flags to see which item(s) were selected by the user.  Use a little perform loop, like this. 

    IF NOT MY-LISTBOX-NONE-SELECTED
      MOVE 0 TO SELECTED-COUNTER

      PERFORM
          VARYING MY-LISTBOX-SDX FROM 1 BY 1
          UNTIL MY-LISTBOX-IDX > MY-LISTBOX-MAX
            OR  SELECTED-COUNTER NOT < MY-LISTBOX

        IF MY-LISTBOX-SELECTED (MY-LISTBOX-SDX)
          SET MY-LISTBOX-IDX TO MY-LISTBOX-SDX
          MOVE MY-LISTBOX-VAL (MY-LISTBOX-IDX) TO mydata-selected
          ADD 1 TO SELECTED-COUNTER
        END-IF

      END-PERFORM
    END-IF

If you use the value in MY-LISTBOX-MAX to terminate the perform, your code won't have to be modified if you change the number of elements in the list...  You could also count how many selected items you've processed, and stop the loop when it's equal to MY-LISTBOX.

Remember - it's possible to select more than one item from a listbox, so be sure to examine the entire list when you look for selections!

Related topics:


© 2000-2019 Norcom, all rights reserved 

TOC

Send feedback to Norcom