List Variables Calculator
List Variables
PowerOne can handle multiple data types. One of those is lists. Lists are used when there is a finite set of options you want the user to choose from, or if a text description makes more sense than a raw number.
List variables are defined similarly to number variables but include a list of options in braces { }. The options within a list are defined as a text description and an optional value. The description and value are separated by a colon, if the value is provided, and the options are separated by semi-colons. The value assigned to the number variable portion serves as the default value.
[https://.../t/help_variables|Learn more about variables].
Creating Lists
Simple Lists
Since lists are replacements for numbers, they are defined the same as numbers with one addition, a list of options in braces:
Notice the first portion is the same as a number definition where the default value is 3. The list itself follows the value, is placed in braces { } and each list option is separated by semi-colons (;).
When viewing this in the template, the list will replace the number field. Lists translate to numeric values internally where the first list option is 1, second is 2, third is 3, etc. By assigning Payment Timing to 3, Monthly is chosen automatically as it is the third option in the list. This value can be used in subsequent calculations and can be calculated itself:
Payment Timing = 3
Payment Timing's Value =
Advanced Lists
In the list above, each option is automatically assigned a value where the first list option is 1, the second is 2, etc. Sometimes that makes sense and sometimes it makes more sense to assign the values yourself. For instance, in the example above, we know the calculation requires Quarterly to be 4, Monthly to be 12 and Bi-Monthly to be 24:
To assign values to each description, add a colon followed by the value after the description. Values can be any number, whether 4 or 4.25, although each list item must have a unique value within its list. Notice the default value changed from 3 to 12 since Monthly is now 12 instead.
Not all options need a custom value, however. The first description, Annual in this example, will automatically be 1 if skipped:
Skipped values elsewhere in the list will always be assigned to 1 plus the previous value. For instance, in this case, Monthly would be assigned 5:
Again, notice the default value needs to be 5 as well so Monthly is selected.
Payment Timing = 5
Payment Timing's Value =
Using Semi-Colons and Colons in List Items
Any character available for typing into a word processor is applicable for a list option's description. However, semi-colons and colons are used to separate list options from each other and descriptions from their values, respectively. To use semi-colon and colon in your description, escape each with a back slant (\; or \:) before the punctuation mark.
Default Values
Default values, while recommended, are optional. If no default value is provided then the value in the template is displayed as a blank space. Without a default value, the Payment Timing example from above:
appears as follows in the template:
Payment Timing =
Descriptions
While list variables are similar to number variables, they cannot include currency symbols nor percentages. Like number variables, however, they can include descriptions. Descriptions will appear between the value and list options, although you can enter it after the list as well. PowerOne will move it. The following example:
will appear as follows in the template:
Memory = 4096
While the GB description is separate, it could also be apart of each list option's description:
Memory = 4096
These two examples are identical internally but create a visual difference with regard to how much is underlined and what appears in the list itself once selected.
List Math
List values are treated similarly to number variables. The value of the list option selected is the current value of the variable. This value can be used directly in an equation. For example, the following template will calculate the Total given a Bill and Tip. The source code:
will appear as follows in the template:
Bill = 40
Tip = 0.2
Total = 48
It is also possible to calculate the value for a list. The value must match one of the list options, however, to get a result. In the example above, change Total to $50 and calculate Tip by selecting [icon--app-unknown-inverse | unknown or unsure value button]. You will receive an error because the calculated tip, .25, is not an option in the list.
Errors
There are two potential errors when working with lists. The first is when a duplicate list item is found. In this case, the duplicate will be reported in the list itself, indicating the duplicate value:
This error is most common when some values are designated and some are not, as in the example above. In this case, Big Sister will be calculated as 2 (Mom is set to 1 and Big Sister would be one more than that, or 2), which is the same as Dad. Select the row to see the error, which appears next to Big Sister indicating both the error and the duplicated value:
My Family List = 1
The second error may occur on assignment. If the default or calculated value for the variable is not in the list, an error will appear as the currently selected option. If My Family List is set to 50 by default, which is not a value in the list:
then the following appears in the template. This error also indicates the missing value:
My Family List = 50
Duplicate List Values
List item values must be unique within its list. The reason list item values cannot be duplicated is because the value is used to determine which list description to show. This means the order can be changed without impacting anyone's calculations but also means duplicates are not allowed.
Sometimes, though, it would be advantageous to have duplicate list values. For instance, creating a template that estimates calories burned for various activities means many of those activities have the same values. Calories burned takes into account the weight, exercise time and an exercise factor, but many of those factors are the same. Here's a sample:
- Aerobics : 60
- Basketball: 80
- Bicycling: 60
- Calisthenics: 45
- Skiing: 83
It would be nice to enter the following:
This won't work, though, because Aerobics and Bicycling have the same value. The easiest solution to this is to use a table coupled with a list:
In the template this appears as follows:
Exercise Type = 1
Exercise Factors = [60; 80; 60; 45; 83]
Factor = 60
Since the Exercise Type's list is indexed the same as the Exercise Factor's table, the lookup to determine the factor to use in the calculation is straight-forward.
Keywords
Payment Timing
Payment Timing's Value
Payment Timing
Payment Timing's Value
Payment Timing
Memory
Memory
Bill
Tip
Total
My Family List
My Family List
Exercise Type
Exercise Factors
Factor
-------------