We have previously looked at the IIf() function for label expressions. The IIf() function allows you to form a simple conditional expression. This can be used to ensure the value returned meets a certain condition. As an example, you only want to show a label for the records where the value in column AGE is higher than 50:
IIf(AGE > 50, AGE, "")
This means that if the value in the AGE column is higher than 50, this value will be returned. Otherwise, an empty string will be returned.
The IIf() function has a bigger brother. We will take a look at the bigger brother called Cond() in this article.
Happy #MapInfoMonday!
The function Cond()
This is the syntax:
Cond( expression, search, result [ search, result ] ... [, Default ] )
expression: The expression you want to evaluate.
search: The value that the expression will be compared to.
result: The result for the search value.
You can use it in two ways.
One allows you to compare the expression to each searchvalue. If an exact match is found, the result for that search is returned.
The other allows you to have a logical expression for each of the search values, and when one is true, the result for that search is used.
I find the first one a bit limiting, as you need to have exact matches. The second allows more flexibility.
A basic example of the first:
Dim sName As String
sName = "Eric"
Print Cond(sName, "Peter", "Name is Peter", "Eric", "Name is Eric", "Mus", "Name is Mus", "Not Found")
The above small script would return "Name is Eric" as the current value in the sName variable is Eric. I'm sure there are good use cases for the way of using it too.
The second allows, as I said above, more flexibility as it allows you to use expressions for the search values. Let me give you an example:
Dim nAge As Integer
nAge = 21
Print Cond(nAge, nAge<16, "1. Children", nAge<65, "2. Working Age", "3. Retired")
For the current value of 21 the expression returns "2. Working Age".
This is a very basic example that, of course, could be built out for more age groups. If I had used the same structure as above, I would need one search value for each possible age. That would give a bit more than 100 search values. By using an expression instead, I can limit it to the number of age groups I'm looking to split my age into.
You can use this to split your records into several age groups via a thematic map.
The trick is to use an expression instead of a column for your thematic map.
In the Expression dialog below, you can see that I have switched my nAge variable to my AGE column.
Update Folks
Set AgeGroup = Str$(Cond(AGE, AGE<16, "1. Children", AGE<65, "2. Working Age", "3. Retired"))
This question was raised by @John Ievers from our partner CDR Group.
I did mention this last week, but I wanted to highlight it again. The Precisely support website has undergone several updates over the past year.
I encourage everyone to explore the latest website features, including AI-powered search capabilities and our redesigned product help pages: Product Help – Precisely Support
Also note that when you use the search capability here in the Knowledge Community, the AI search will automatically also search other support websites and articles.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------