Question: I have one data field on the report, the data sample like following:

"75,80,80,80,92"
"75,80,80,80,93"
"75"
"75,80"

I created another expression field to try retrieved only third pair digits if length =14, so I have

```
=IIf(Len([CRCase.dtcase_Attributes])=14, Substring(Replace([CRCase.dtCase_Attributes],',',''), 4,2),'empty') 

```

when I run the report, I could get "80" for first two rows, but error for bottom two. Is there any way to workaround?

Thanks.

Answer: 
.: EDIT :.
==========

If you have a Universal app that doesn't have a MainWindow object you'll probably want to tap into the "Suspending" event:

```
appObject.Suspending += (s, a) =>
        {
            SaveTheData(); // I really like my data and want it for later too
        };

```

or

```
public App()
    {
    /*
        stuff
     */
    Suspending += (s, a) =>
        {
            SaveTheData(); // I really like my data and want it for later too
        };
    }

```

.: Original :.
==============

Add a handler to your MainWindow "Closing" event to save your data. Once "Closing" has finished, "Close" should fire normally.

```
theMainWindowObject.Closing += (s,a) =>
    {
        SaveTheData(); // It's precious!
    };

```

I have something similar to this in one of my smaller applications where in the constructor for MainWindow I put the above snippet substituting "theMainWindowObject" for "this" so that it references itself

So I have:

```
public MainWindow()
    {
    // Note: "this." isn't necessary here but it helps me with mental accounting
    this.Closing += (s, a) =>
        {
            Save();
        };
    }

```

If you're just saving one or two properties and don't have any crazy logic going on you can just drop it right in the handler:

```
public MainWindow()
    {
    Closing += (s, a) =>
        {
            Properties.Settings.Default.SettingsPopupX = mySettingsPopupObject.GetX();
            Properties.Settings.Default.SettingsPopupY = mySettingsPopupObject.GetY();
            Properties.Settings.Default.Save();
        };
    }

```
If you want to manage your Application Lifecycle have a look at this MSDN article: <https://msdn.microsoft.com/en-us/library/windows/apps/mt243287.aspx>
In general you don't have a "close" event in Windows Apps. Your App will be suspended when Windows or your user wants to close it. Using the `ApplicationExecutionState` [(see more)](https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.applicationexecutionstate.aspx) enum you can find out who (windows or your user) closed the app.

Hope it helps!