# Button bar active segment by calculation

**URL:** <https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367>\
**Category:** Questions\
**Tags:** button-bar\
**Created:** [February 7, 2023, 11:06pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367 "2023-02-07T23:06:59Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 7, 2023, 11:06pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/1 "2023-02-07T23:06:59Z")

</div>

Hi there,

the Active segment of a button bar can be set using a calculation, which is great.

My question is when is this calculation evaluated, what triggers it ? I am breaking my 🦷 on this.

Thanks

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 8, 2023, 12:29am UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/2 "2023-02-08T00:29:22Z")

</div>

I don't think we can know exactly but we can guess:

1. Layout Load
2. Record Load
3. Is the button in a location that will be visible (or is it on an object that is not being displayed)?
4. Does the button have a hide calc? Will it be visible?

You know that the result of the calculation must be the name of the button segment to be marked as active, yes?

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 8, 2023, 1:16am UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/3 "2023-02-08T01:16:51Z")

</div>

3- It is displayed, but the Layout has graphics objects that I don't understand purposes. I need to redo the Layout  
4- No hide calc

The calculation is set to a global variable, and when I change the value of that variable, I refresh the Button bar. Could the use of a global variable be problematic, it is set to a segment name ?

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 8, 2023, 1:48am UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/4 "2023-02-08T01:48:29Z")

</div>

In a simple test file this code works.

```auto
Set Variable [$$activeSegment ; "NavBtnBar_Invoice"]
Refresh Object ["NavBtnBar"]

```

1. Buttonbar is named "NavBtnBar". It has three segments, labelled "Invoice", "Customer","Product"
2. The button segments are named (object name not button label) "NavBtnBar\_Invoice", "NavBtnBar\_Customer", "NavBtnBar\_Product"
3. Active segment calculation is "$$activeSegment"
4. create a script using the script steps above.

To see the active button segment being changed, select any segment except "invoice" then run the script. If you have set everything up correctly the "invoice" segment is displayed in the active state.

Edit:

1. if the calculation uses a field in the current record, and that field is modified, that would trigger an immediate update.
2. the calculation can use a field in a related record, and that will trigger an update
3. rearrange the steps above for easier understanding

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 8, 2023, 9:58pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/5 "2023-02-08T21:58:09Z")

</div>

@Malcolm

I have tested this with a different Button Bar, lets call it **BB2** and it's working. But it's not working with the one I want to use this.

**First here is the context.** I have a Button Bar with 9 segments, lets call it **BB1** , 9 being the maximum. At this time only 6 of them are used. I don't want to hide the 3 unused segments because I don't want the use segments to resize. How do I do this ? I use Conditional Formatting to have the unused segments "kind of invisible". You can't see them, but if you click on of the _hidden_ segments the active segment is automatically changed. When that happens, I want to change back the active segment to the one that was active before the hidden segment was touched/clicked. But for for this Button Bar it does not work.

For **BB2** , the one that works, I changed the name of the segments, and I can see these names in the popup menu used to set the default active segment. The names are "Fr" and "En".

But with **BB1** , the names of the segments are not shown in the popup menu. These are the names as seen in the left pane:

![BBar Named Segment 1](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/7/74c9dc00fe75c369046eac01063405da5fe67b7f.png)

As you can see the names are "SE01" to "SE09".

Now, look what I get in the popup menu:

![BBar Named Segment 2](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/8/84068142e0deaffcdd6108fa8bd87c12eaf9f66e.png)

The default object names. By the way Specify is set to $$MySegment. When an _invisible_ button is clicked, I set $$MySegment to "\<Segment m" & "x" & "\>" where x is the segment number. And the previously active segment is not back active.

You said

> [@Malcolm](#):
>
> Select any segment except "invoice"

why ?

In my case, I guess that the contents of $$MySegment is not changed when clicking an _invisible_ button.

Do you understand what's going on ? Regarding the button names not reflected in the popup menu, I cleared the name I specified, and set them back, but is still get .

Thanks

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 8, 2023, 10:35pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/6 "2023-02-08T22:35:57Z")

</div>

_Why select any segment except "invoice"?_ So that you can see clearly, when the script runs, that the active segment changes from the active segment to "invoice".

> [@planteg](#):
>
> Specify is set to $$MySegment. When an _invisible_ button is clicked, I set $$MySegment to "\<Segment m" & "x" & "\>" where x is the segment number. And the previously active segment is not back active.

Are you confusing the button _segment name_ with the button _segment label_? The screen shots are showing the button segment labels. The button segment name is set in the first inspector panel.

![ObjectName](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/2/2664a56db17234d7bc625facd3d7dccf5b88a141.png)

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 8, 2023, 10:50pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/7 "2023-02-08T22:50:37Z")

</div>

> [@Malcolm](#):
>
> Are you confusing the button _segment name_ with the button _segment label_?

No I am not confusing. If you change the name in **Objects** in the left Pane, this will be reflected in the **Name** field you show. You may also do it the other way.

There is another difference between the Button Bars: the one that works is horizontal, the one that don't work is vertical. I change the horizontal on to vertical and it still works.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 8, 2023, 11:37pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/8 "2023-02-08T23:37:55Z")

</div>

> [@planteg](#):
>
> These are the names as seen in the left pane:
> 
> ![BBar Named Segment 1](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/7/74c9dc00fe75c369046eac01063405da5fe67b7f.png)
> 
> As you can see the names are "SE01" to "SE09".

If these are the object names of the button segments then they are the names that you want to set $$MySegment to.

Be careful to ensure that they are the object name. The object pane will display the Object Name if one is present. But use other values if the object name is empty. If the object name is empty, in the case of buttons, it will display the segment label. If the button label is a calculation, it displays "calculation." If the button label is empty, it displays "Button".

 ![ButtonSegmentName](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/5/5326de64247e7f89da7b2a4fd40344e595c6f60e.png)

In the picture, the first segment is labelled "a", and has the name "SEG01". None of the other segments have names. The second segment has a simple string label "b". The third segment has no label at all. The fourth segment is a very simple string calculation. The label is not evaluated, it is shown as "Calculation". (If you use numbers as your button labels they will be interpreted as calculations.)

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [February 9, 2023, 12:51am UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/9 "2023-02-09T00:51:07Z")

</div>

> [@planteg](#):
>
> I don't want to hide the 3 unused segments because I don't want the use segments to resize.

I use a different technique to hide button bar segments without them resizing. Let's say I want a button bar with six segments. I then make a button bar with twelve segments. Six of these are active segments. The other are inactive segments – they do nothing. I then use hide conditions to display the active and inactive segments I want. You could style the inactive segments in such a way as to make them transparent.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 9, 2023, 3:49pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/10 "2023-02-09T15:49:00Z")

</div>

I guess we agree that my segments all have a name (object name). I did try this (segment "SE02" being current):

```auto
Set Variable [$$Segment ; Value: "SE01"]
Refresh Object [Object Name: "MyButtonBar"; Repetition: 1]

```

That didn't work. I also tried refreshing the button itself:

```auto
Refresh Object [Object Name: "SE01"; Repetition: 1]

```

That also didn't work.

I keep thinking that the fact the popup menu for Active segments does not display the object names but indicates that the Button Bar is _broken_. If only I was able to get the Active segment from the Button Bar, I could confirm or not my hypothesis.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 9, 2023, 6:16pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/11 "2023-02-09T18:16:14Z")

</div>

You have a working example, rebuilding a new button based on that cannot be as long as this thread.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 9, 2023, 7:47pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/12 "2023-02-09T19:47:12Z")

</div>

It's completely normal for the active segment popup to display \<Segment x\>. It does it whenever the label is NOT a simple string.

The image below shows the active segment pop-up for the screen shot shown above. When the label is a string, it displays the label. When the label is empty, or is a calculation, it displays \<Segment x\>

![SCR-20230210-c2c](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/c/c4820c935045144cb216e04b607f079f8d771064.png)

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 9, 2023, 9:31pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/13 "2023-02-09T21:31:19Z")

</div>

> [@Malcolm](#):
>
> It's completely normal for the active segment popup to display . It does it whenever the label is NOT a simple string.

Spot on ! All the labels are calculated. I am looking for threads in the Community about what I am trying to do. I found this for example:

> **You can set the active segment on the button bar to false** , give the button bar an object name in the inspector, then use refresh object on the button bar after the button is used.

Emphasis is mine. What that means is that setting the active segment programmatically is not that easily done (is rocket science).

I have a few things to test plus more reading to do.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [February 9, 2023, 11:14pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/14 "2023-02-09T23:14:01Z")

</div>

> [@planteg](#):
>
> > setting the active segment programmatically is not that easily done (is rocket science).

It is very easy. Using a global variable as the calculation for the active segment, and two lines of script, you have complete control over the active state of the button. [[See my post above]](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/4)

Many people seem to have the wrong expectation of `Refresh Object[]`.

`Refresh Object[]` does not update the layout to display the object in its original/default state.

`Refresh Object[]` _updates the layout to display an object in its **current** state_.

Buttons are _usually_ being displayed in their current state, when the current state matches the display state the `Refresh Object[]` script step doesn't affect the layout display. The only way that you'll ever see a mismatch between the _current state_ and the _display state_ is when a button bar's active segment has been defined by specifying a calculation. When the result of the calculation has been changed, usually by a script, possibly by data entry, a mismatch can occur. To ensure that the display state of a button properly reflects the current state of the calculation use the `Refresh Object` script step to update the display.

[HowToSelectActiveSegments.fmp12](https://the.fmsoup.org/uploads/short-url/xOCUBD9Kje0HUQpCfwygIG00OK6.fmp12) (228 KB)

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [February 14, 2023, 7:47pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/15 "2023-02-14T19:47:34Z")

</div>

Note: Any button bar segment calculation that 1) uses a GET () that is record level relevant and 2) is in a portal, will not work - at least all those I have tried so far. For whatever reason, the segment calc looks at the layout base context and NOT the portal context. Pull the same calc outside the portal located button, and it works fine.

Also, button bar active states in a list view, highlights the button in every row. To resolve, set the button bar dialog's specify calculation to 1 (or true), and only the button the row being clicked, displays as active.

Any given button bar segment can be conditionally formatted individually, if the formula is set to TRUE. Makes it easy to hide icons, for instance, on selective buttons.

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [February 24, 2023, 5:37pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/17 "2023-02-24T17:37:16Z")

</div>

Sorry for the delay in answering. Here is the solution, and it works very well.

Each Button on the Button Bar must be given a name, if not it will not work. See this screen capture

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/4/44c3bfd9289dcbce2f75ee51f38682cd4ab355f2.png)

1. The top button on the bar is selected
2. In the the left most Tab of the Inspector, the Object name of this button, not what the button displays, is set.
3. In the Objects Tab of the left pane in Layout mode, the name is displayed. If something else is displayed, the the button Name is not set, and it will not be possible to programatically set the active button.

One more setting is needed on the Button Bar properties

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/d/dfa0e15022d47309b21003076402ceb474cd4012.png)

The Active Segment is specified in this field. Note the value is **Specify...**. Lets see what the PopupMenu choices are

![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/e/edd85b3196b80978b994f9f25efe4bbee0363533.png)

Click on **Specify...** and

![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/5/5f98a48d5d03159cc2f118d928c5814e2e54c0c1.png)

we have the Specify Calculation window ! I use a global variable that is set to the name of the specific button, for example "SE01". And that's it !

---

<div class="post-metadata">

**Author:** ![barefoot](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/barefoot/32/2553_2.png) [@barefoot](https://the.fmsoup.org/u/barefoot)\
**Post date:** [July 28, 2024, 6:17pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/18 "2024-07-28T18:17:02Z")

</div>

Glad i found this. I did already spend all Sat, Sum of this trying to figure it out myself. Very disappointingly this is a lot of work of hardwiring stuff. Thanks to you and to Claris no thank you!

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [July 28, 2024, 10:23pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/19 "2024-07-28T22:23:26Z")

</div>

Why no Claris thank you ? I used what Claris provided to full extent, and it worked pretty good. I used the same layout for many _screens_ that had different menus - there were two button bars - and it each time and it was fast on a fifth generation iPad. I bought a new iPad 10th gen because the old one was slower and slower in other applications.

True that would be nice to have composite layouts, where a layout could embed sub-layout(s). I don't know it that's possible with FileMaker Pro, but it's already possible with Claris Studio which is very impressive !

---

<div class="post-metadata">

**Author:** ![barefoot](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/barefoot/32/2553_2.png) [@barefoot](https://the.fmsoup.org/u/barefoot)\
**Post date:** [July 28, 2024, 11:19pm UTC](https://the.fmsoup.org/t/button-bar-active-segment-by-calculation/3367/20 "2024-07-28T23:19:18Z")

</div>

I didn't ask for composite layouts just ButtonBars in a sense where I don't need to hardwire every segment with object names and explicitly address them and setup individually. The good old repeating fields can do though. How they behave is counter intuitive especially if you place the same button bar on a different layout you open in a new window. The default active segment won't stick. But your "trick"/work-around with explicitly setting them to a global variable and refreshing the individual object did it. ROCKET SCIENCE!
