"No Holding Back FileMaker Blogging"


Navigation:


Support this site by clicking on a sponsor below or becoming a patron!



Beginner, Intermediate and Advanced Video Training


Become a patron of this FREE web site!


Recent Blogs:

Form Letters in Browse
Form Letters in Browse

Context & Relationships
Context & Relationships

Parsing for Features
Parsing for Features

Parsing A Web Form
Parsing A Web Form

Data Parsing
Data Parsing




$10.00 Beginner Video Training


Quick Tip:

Merge Field Madness
I'm sure most of you have run into this problem at one point or another. You wish to place a merge field on the layout, but the name of the field extends beyond your available layout space. While the data still displays correctly in browse mode, the length of the merge field covers up nearby objects, making it difficult to work in layout mode. One solution is to shorten the name of your field. If you can't or don't want to do that, try changing the font size of your merge field so the text block fits in your available space. Keep the first less-than sign in your chevron (e.g. <) the font size you want to display the merge data. Even though most of the text in your merge field is a tiny font size, the first merge field character will set the size for the data. Pretty cool. This can also be done with symbols that are surrounded by curly brackets (e.g. {).



Tips & Tricks Videos


Fun Stuff:

Claris and FileMaker CEOs
Bill Campbell  1987 to 1995
Guerrino De Luca  1995 to 1997
Dominique Goupil  1997 to Present



Create a FileMaker Calendar



FREE FileMaker 17 Videos



Document Management Videos



Create a Complete Contact Manager



Support this site by becoming a patron!







RSS Feed
Weight Lifting
Level: Advanced
Version: FileMaker 17
Category: Calculations
Tuesday, September 18, 2018
This technique has no real use in the real world. Say what? Yes, you read that correctly! Think of the technique I'm about to cover as weight lifting for your FileMaker mind. It's about solving a complex problem, learning new scripts steps and functions, and generally getting smarter so the next time you tackle a problem you'll be more prepared. I believe in conditioning so much, I often write scripts from scratch I could easily copy and paste. But I digress. All I can say is if you want to build up your FileMaker muscles and learn some new tricks then keep reading.

Weight Lifting

The Challenge
The goal of this programming exercise, is to change the font characteristics of any selected text using scripts and calculations. That includes color, style and size. While the font could also be changed with this technique, the three characteristics will be enough to help you if you feel the need to change the font too. But remember, this technique is for increasing your brain capacity and not for real world application.

Weight Lifting

Why it's Useless
If you want someone to be able to change the font characteristics in browse mode, just have them use the Format menu. I normally hide this menu with Custom Menus cause changing characteristics in browse mode overrides layout settings. In other words, if someone changes the characteristics in browse mode then no matter where that field is used, it will use the browse settings. What you end up with is a hodgepodge of font characteristics that make print or other data entry layouts indiscernible.

Weight Lifting

I'm off topic again but I think this is a very important point to make. The only time I see this as a viable solution is in an article I just wrote about form letters. Otherwise, it's never a good idea to allow font changes in browse mode and therefore a waste of time to program the solution covered in this article. I only present this technique to strengthen your FileMaker mind.

The Interface
As with most interactive interfaces, I'll be using global fields. I'll use three global fields to represent Size, Color and Style characteristics. Create xsize as a global number field and the other two as global text fields.

xsize
xcolor
xstyle


I always find it best to offer an example of what the interface might look like in order to better understand where we will be going in this article. This is especially true in this article since you probably never thought about scripting this process. Basically, the idea is to make your size, color and style choices, select your text and then click a button to apply the settings.

Weight Lifting

Grabbing the Text
Let's build the formula that applies the font characteristics in pieces so it's easier to understand. The first step is to grab the selected text. Since we want the formula to adapt to any text field, we'll use functions that allows for indirection.

Middle(

GetField(Get(ActiveFieldTableName) & "::" & Get(ActiveFieldName));

Get(ActiveSelectionStart);

Get(ActiveSelectionSize)

)

The great thing about these functions is they need very little explanation because they have been named by FMI so well. All we need to do is return these Get functions to the Middle function and it extracts the selected text. The GetField function is also required to evaluate the text as a field name. Otherwise, it's just text that has the same name as a field and not a reference to a field. We'll see this later on as well but with a completely different function.

FYI: There is a function called Get(ActiveFieldContents) but it grabs all the text from the field. All we want is the selected text.

Text Formatting Functions
We'll start with the text size since it's the easiest of the three to construct. To change the font size, we'll employ the TextSize function. The TextSize function is easy to use since a character can only have one size applied to it. If you apply a new size, it overrides the previous size. All you need to do is refer to a field, instead of hard coding a number, and you have a formula that adjusts to the input in a field.

TextSize(<Active Field Selection>; MYTABLE:xsize)

If you're wondering what <Active Field Selection> means, it's simply a reference to the Middle function formula discussed above. I just used a reference so we can focus on the TextSize portion of the formula.

FYI: There's a counterpart to TextSize called TextSizeRemove which sets the size of the font back to the default. The default is whatever is set in layout mode.

The next step is to feed the result of the TextSize function into the TextColor function. To make the formula as adaptive as possible, let's create a table called COLORS so the RGB values don't have to be hard coded into the formula. The table should contain a text field for the name of the color as well as a three number fields for red, green and blue.

color
red
green
blue


You'll also need a relationship between MYTABLE and COLORS. Use the xcolor and color fields as the keys.

Weight Lifting

You'll also want to create a value list based on the contents of the color field so any color that gets added to the table will automatically appear on the popup menu attached to the xcolor field.

Changing the text style is the most complex part of this exercise. The TextStyleAdd function is simple enough but we might want to feed in multiple styles at a time. For example, text could have both bold and italic styles applied at the same time. In order to allow for multiple selections, a check box will be used for the interface on the xstyle global field.

The problem is how to efficiently feed the multiple values into the TextStyleAdd function. If you read the online help that comes with FileMaker, it shows an example like the following:

TextStyleAdd(FirstName; Bold+Underline)

Instead of using square brackets for each style, as with other functions, a single parameter with plus signs is employed. At first this is perplexing but then you think about how a check box stores values as a return-separated list. With that knowledge, a simple substitute could change the return-separated into a list separated by plus signs.

TextStyleAdd(@Color; Substitute(MYTABLE::xstyle; "¶"; "+"))

Unfortunately, this combination of functions doesn't quite work. One more function needs added to the equation.

TextStyleAdd(@Color; Evaluate(Substitute(MYTABLE::xstyle; "¶"; "+")))

The Evaluate function acts much like the GetField function covered earlier in that it converts the string of styles separated by plus signs from text into a value. Here's the complete formula.

TextStyleAdd(@Color; Evaluate(TextSize(

TextColor(

TextStyleAdd(

Middle(
GetField(Get(ActiveFieldTableName) & "::" & Get(ActiveFieldName));
Get(ActiveSelectionStart);
Get(ActiveSelectionSize));

Evaluate(Substitute(MYTABLE::xstyle; "¶"; "+"))

);

RGB(COLORS::red; COLORS::green; COLORS::blue)

);

MYTABLE::xsize

)

However, I prefer the formula with the Let function since it's easier to read and edit.

Let(

[@Selection = Middle(
GetField(Get(ActiveFieldTableName) & "::" & Get(ActiveFieldName));
Get(ActiveSelectionStart);
Get(ActiveSelectionSize));

@Size = TextSize(@Selection; MYTABLE::xsize);

@Color = TextColor(@Size; RGB(COLORS::red; COLORS::green; COLORS::blue));

@Result = TextStyleAdd(@Color; Evaluate(Substitute(MYTABLE::xstyle; "¶"; "+")))];

@Result

)

TIP: All text formatting can be removed from a field using the TextFormatRemove function. You can employ it in a script but I prefer an auto-enter calculation so it removes all formatting from those web browser pastes as soon as the user exits the field <TextFormatRemove(Self)>.

Bring It All Together
Let's take the formula we just constructed and place it in a script. There are a few extra steps but place close attention to the Insert Calculated Result step which contains the formula we've been covering.

Weight Lifting

There are a couple of things that need to be done before applying the formula. The first step is to check that text is selected. The Get(ActiveSelectionSize) is checked for two possible states. If no field is active, Get(ActiveSelectionSize) will return a null value. However, if a field is selected but no text is selected (just a blinking cursor), the Get(ActiveSelectionSize) will return a zero.

Before applying the text formatting, the Get(ActiveSelectionStart) and Get(ActiveSelectionSize) are both recorded into a variable with a simple space separation. The reason is the Insert Calculated Result loses the active selection and must be restored. Therefore, the Set Selection follows the Insert Calculated Result step and restores the highlighted text.

It's Not My Fault
I told you at the beginning of this article that this technique was useless so don't blame me if you feel like you wasted your time LOL. Hopefully you understood the purpose and can now flex your FileMaker muscle a little bigger with the knowledge you gained. Maybe you won't use any of the techniques covered here tomorrow but I'm sure some day you'll reach back into the vault and pull out some tidbit to create your own custom solution.

Author:
John Mark Osborne
jmo@filemakerpros.com
www.databasepros.com

Example File:
FORMAT.zip

This blog is completely free. Please support it by clicking on one of the advertisers at the left side of the window or becoming a patron. Thanks so much!

Add Comment:

First Name: *
Last Name:
Email: *
Web Site:
Comment: *
 Email Addresses will not be shared on the web site!