Step 3 Build a Dynamic Working List of Selected Items

VLF Windows Application Development

Step 3. Build a Dynamic Working List of Selected Items

VFW052 – Build a Working List of Selected Items

In this step you will extend your Weekly command handler by defining a working list. The ItemGotSelection and ItemLostSelection event routine will be extended to add or delete entries to/from the dynamic working list.

A Dynamic Save push button will be added to PANL_1. When clicked this button will write a comma separated file from the dynamic working list.

1.  Define a work field called KEYEMPNO which refers to field EMPNO for its definition. This will be used to store EMPNO in the working list

2.  Define a work field RETCODE which refers to field IO$STS for its definition.

3.  Define a working list DYNAMIC containing fields KEYEMPNO, SURNAME, GIVENAME and SALARY. Specify the number of entries as *MAX. Define the list Counter as LISTCOUNT.

     Note: *MAX denotes the maximum list sized is only limited by the execution platform. For *MAX, the working list uses memory dynamically.

     Your code should look like the following:

Define Field(#keyempno) Reffld(#empno)
Define Field(#retcode) Reffld(#io$sts)
Def_List Name(#dynamic) Fields(#keyempno #surname #givename #salary) Counter(#listcount) Type(*working) Entrys(*max)

 

4.  Modify the ItemGotSelection event routine:

a.  Look in the DYNAMIC working list (LOC_ENTRY) for the selected employee number. Use Where() to compare KEYEMPNO with EMPNO.

b.  If not found, add an entry to list DYNAMIC. Be sure to first change field KEYEMPNO to the value of EMPNO (ADD_ENTRY).

5.  Modify the ItemLostSelection event routine:

a.  To look in the DYNAMIC working list for the selected employee number using LOC_ENTRY with a suitable Where() parameter.

b.  If found, change KEYEMPNO to EMPNO and delete the entry from list DYNAMIC (DLT_ENTRY).

6.  Add a push button to the bottom panel (PANL_1) and change the Name to PHBN_DYN. Change the Caption to Dynamic Save.

7.  With the PANL_1 selected, select the Design ribbon..

a.  Click on New Layout and click on Flow Across to add a flow across manager to this panel.

b.  On the Layout Helper tab, click on the right hand blue paper clip button, to Attach all children to the layout manager.

c.  On the Layout Manager Details tab, select the Category / Margins and use the All setting to define all margins as 6 pixels.

d.  Your design should look like the following:

8.  Create a Click event routine for the push button PHBN_DYN. Add logic to:

a.  Check if LISTCOUNT is greater than zero

b.  Use the TRANSFORM_LIST BIF to create a comma separated file. Place the in C:\temp. For example:

if (#listcount > 0)
Use Builtin(TRANSFORM_LIST) With_Args(#Dynamic 'C:\temp\iiiDynamic.csv' O) To_Get(#retcode)
Endif

 

Hint: Use the F4 Command Assistant to complete the USE command.

c.  Check if RETCODE is OK. Issue a "Dynamic file saved to . . . " message, or an error message if the save was not successful.

     Your code should now look like the following. New / changed code is highlighted in red, italic.

Evtroutine Handling(#LTVW_1.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#std_texts := 'YES'
Upd_Entry In_List(#LTVW_1)
#TOTSALARY := #TOTSALARY + #salary
#keyempno := #empno
Loc_Entry In_List(#Dynamic) Where(#empno = #keyempno) Ret_Status(#retcode)
If (#retcode *NE OK)

Add_Entry To_List(#Dynamic)

Endif

Endroutine
Evtroutine Handling(#LTVW_1.ItemLostSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#std_texts := *blanks
Upd_Entry In_List(#LTVW_1)
#TOTSALARY := #TOTSALARY - #salary
Loc_Entry In_List(#Dynamic) Where(#empno = #keyempno) Ret_Status(#retcode)
If (#retcode *EQ OK)
Dlt_Entry From_List(#Dynamic)

Endif

Endroutine
Evtroutine Handling(#PHBN_DYN.Click)
If (#listcount > 0)
Use Builtin(TRANSFORM_LIST) With_Args(#Dynamic 
'C:\temp\iiiDynamic.csv' O) To_Get(#retcode)
If (#retcode *EQ OK)

Message Msgtxt(
'Dynamic file save to C:\temp\iiiDynamic.csv')
Else

Message Msgtxt(
'transform list failed')
Endif

Endif

Endroutine

 

9.  Compile your component

10. Execute the Framework and test your new Weekly command handler for the Reports business object. Check that the CSV file is saved with the correct contents. The file will open in Excel if available, otherwise open it using Notepad.

Notes:

If a path is not specified, the TRANSFORM_LIST BIF will save the output file in <sysdir>.

Optional: You could have set the dynamic save push button to Enabled(False) initially and enable the button if LISTCOUNT is greater than zero. Add this logic to the ItemGotSelection and ItemLostSelection event routines.