Global Variable not displaying properly on layout

I use the below script trigger to monitor the front tab in a tab control with four tabs. It runs as a trigger on the tab controls, on ObjectModify. The tab object names are Tab1,Tab2, etc.

Enter Browse Mode

If [ (GetLayoutObjectAttribute ( "Tab1";"isFrontTabPanel")) ]

Set Variable [ $$A; Value:"Name1 tab is in front" ]

Else If [ (GetLayoutObjectAttribute ( "Tab2";"isFrontTabPanel")) ]

Set Variable [ $$A; Value:"Name2 tab is in front" ]

Else If [ (GetLayoutObjectAttribute ( "Tab3";"isFrontTabPanel")) ]

Set Variable [ $$A; Value:"Name3 tab is in front" ]

Else If [ (GetLayoutObjectAttribute ( "Tab4";"isFrontTabPanel")) ]

Set Variable [ $$A; Value:"Name4 tab is in front" ]

End If

It works ok except the global variable $$A does not display properly on a layout. It does not change when I click various tabs.

Script debugger shows the script is working ok, and data viewer shows the $$A receives the correct value for the tab clicked. However, it does not change on the layout and sometimes it changes to the incorrect value. For example, if $$A reads “Name2 tab is front”, when I click say tab3, $$A remains unchanged on the layout, although Data Viewer shows $$A to be “Name3 tab is front”.