Lesson 7: Create a library of reusable functions
Create a library to format money values and to associate category numbers with descriptions.
About this task
When you reference a declaration
in the library from other logic such as a service or handler, you
can include the library name as a prefix. For example, MyLibrary.myLibraryVariable is
appropriate if the library name is MyLibrary and
the library includes the myLibraryVariable variable.
Alternatively, you can include the library name in a use statement
in the other logic and avoid the need to qualify every reference.
In that case, myLibraryVariable is sufficient to
reference that variable.
Create a Library part
Procedure
To create a Library part:
Create the categories array
About this task
categories STRING[] = [
"Rent", // 1
"Food", // 2
"Entertainment", // 3
"Automotive", // 4
"Utilities", // 5
"Clothes", // 6
"Other" // 7
];The value is an array, and as is true of all arrays in EGL, the index of the first element is 1, not 0.
The array
is used in logic that acts as follows:
- Places an expense category into the database in integer form, to save space.
- Places the expense category onto the web page in string form, for clarity.
Create the get functions for categories
About this task
Procedure
Lesson checkpoint
About this task
- Create a Library part.
- Add functions and a variable to a library.