You are on page 1of 1

CTA – Lesson 11 – Object properties / collection

Exercise 11:

VBA (Class Module) Use the pensioners’ data file of exercise 2

Question 1

a) Define a CPensioner Class (in a Class Module) that contains the properties describing
a pensioner (name, birth, type, gender, yearly pension amount).

b) Define a method for the Class CPensioner, that returns True if the pensioner is entitled
to a pension, i.e. he is younger than 85
Define a method that adapts the pension amount to the cost of living. The method has
one parameter (the rate of inflation). When you call the method, then the pension
amount is increased by the rate of inflation.

c) Create a pensioners’ Collection.

d) Count the number of pensioners in the data file (XL worksheet).

e) Loop on all pensioners of the data file, create a pensioner object for each one and add
them to the collection. The pensioner’s name must be defined as a key in the
collection.

f) Ask the user to enter a pensioner’s name (“B98”) or the pensioner’s position (10).
Check if the data entered is numeric. Display the value of the corresponding
pensioner’s properties in a Message box and if he would be entitled to a pension. Ask
the user if he wants to remove the pensioner. If yes, then remove the pensioner from
the collection. Loop until the user wants to stop.

g) Display in a message box the number of the remaining pensioners in the collection,
and the sum of their current pensions (for the pensioners older than 85, the current
pension is zero). Then ask the user to enter an inflation rate. Adapt all the pension
amounts to the inflation (in the collection). Display in a message box the total amount
of the pensions before and after the pension increase.

Question 2

Record & store macros, then link them to buttons in order to:

a) Sort the pensioners by name (ascendant & descendent) in the XL file


b) Sort the pensioners by age (ascendant & descendent) in the XL file.

You can also have a single button and ask the user if he wants to sort in ascendant or
descendent order, and which column he wants to sort.

1/1 CTA / part 1

You might also like