Step 4. Add a Working List

In this step, you will add a working list which will contain entries for the currently selected entries in the list ListEmployees. Entries in the working list will be maintained by the ItemGotSelection event routine adding an entry and ItemLostSelection event routine removing an entry from the ListEmployees. The Compute push button click event will be extended to update a List Count field displayed in the right hand column.

1.  Define a work field in your web page, with the name EmployeeKey with a reference field of xEmployeeIdentifier.

Define Field(#EmployeeKEY) Reffld(#xEmployeeIdentification)

 

2.  Define a working list (Type(*working)), with the name WListEmployees, for fields EmployeeKey, xEmployeeSurname #xEmployeeGivenNames and xEmployeeSalary, with a Counter property of LISTCOUNT and Entrys *max.

Def_List Name(#WlistEmployees) Fields(#EmployeeKey #xEmployeeSurname #xEmployeeGivenNames #xEmployeeSalary) Counter(#LISTCOUNT) Type(*Working) Entrys(*MAX)

3.  On the Design tab, drag the field STD_NUM onto the right hand column.

a.  On the Layout ribbon change Alignment to Top Left and a Flow to Down.

b.  Change margin Left to 10 and margin Top to 20.

c.   On the Details tab, set up its properties as:

Property

Value

Caption

Working List Entries

CaptionType

Caption

Name

EmployeeCount

Width

120

 

4.  This step will use the LOC_ENTRY command. This locates an entry in a list, based on a Where clause. For example:

Loc_Entry In_List(#WListEmployees) Where(#xEmployeeIdentification = #EmployeeKey)

 

5.  Extend the ListEmployees.ItemGotSelection to perform the following:

Locate an entry in the working list WListEmployees where EmployeeKey is equal to xEmployeeIdentification.

If not found:

  Assign the value xEmployeeIdentification to EmployeeKey

  Add an entry to WListEmployees.

End IF

Assign EmployeeCount to zero

     Your code should look like the following. Changes are highlighted.

Evtroutine Handling(#ListEmployees.ItemGotSelection)

#TotalSalary += #xEmployeeSalary

#TotalSalary1 := 0

Loc_Entry In_List(#WlistEmployees) Where(#EmployeeKey = #xEmployeeIdentification)

If (#io$sts *NE OK)

#EmployeeKey := #xEmployeeIdentification

Add_Entry To_List(#WlistEmployees)

Endif

#EmployeeCount := 0

Endroutine 

6.  Add similar code to extend the ListEmployees.ItemLostSelection event routine to delete an entry in WListEmployees if an entry is found.

     Your code should look like the following. Changes are shown in red.

Evtroutine Handling(#ListEmployees.ItemLostSelection)

#TotalSalary -= #xEmployeeSalary

#TotalSalary1 := 0

Loc_Entry In_List(#WlistEmployees) Where(#EmployeeKey = #xEmployeeIdentification)

If (#io$sts = OK)

Dlt_Entry From_List(#WlistEmployees)

Endif

#EmployeeCount := 0

Endroutine 

7.  Add code to the Compute.Click event to assign EmployeeCount the value Listcount. The working list's Counter parameter is automatically maintained as entries are added or removed.

     Your code should look like the following. New code is shown in red.

Evtroutine Handling(#Compute.Click)

Selectlist Named(#ListEmployees)

If (#ListEmployees.CurrentItem.selected = true)

#TotalSalary1 += #xEmployeeSalary

Endif

Endselect

#EmployeeCount := #LISTCOUNT

Endroutine

 

8.  Compile your web page.

9.  Test your web page. Select a number of employees and click the Compute button. The Working List Entries field should display the number of entries currently selected.

     Changing the selected employees should reset EmployeeCount to zero.