Can I automatically clear data after it has been autosaved by a Macro in LabChart for Windows?

This is an advanced solution.

It is possible to use LabChart's Macro functionality to automatically clear data after saving the current data as a separate .adicht file, and then resume recording. The periodic saving and 'cleaning' the file prevents any slowdown in LabChart due to having an excessive amount of data in a single file due to long recording times / high sampling rates (>24 hours with multiple Channels).

To add the data clear to your Autosave Macro, open the Macro by going to Macro | Manage | Select the Macro | Click 'Edit', and copy and paste the below Macro code immediately after your Autosave code:

        Call Doc.SelectAll ("Chart View")
        Call Doc.Clear ("Chart View")


! Important note - make sure this comes after the Autosave - if it is placed before the Autosave code, you will wipe your data and then save the empty file

Note that it is easier to copy and paste the code rather than writing it into the macro. When using the 'Select All' command when Recording a Macro, it enters a size for the selection, meaning the 'Select All' part of the Macro will sometimes not work correctly.

Note: You may still need to close and re-open the LabChart file every few days (depending on hard drive space). This is because even though the data is cleared, LabChart writes all recorded data to a buffer file (for recovery in case of a crash), which will build up over time, filling your hard drive.

A example Autosave and Autoclear Macro may look like the below, which saves and clears the data every 15 seconds (the red text indicates the save location for the Autosave, which will be specific to your computer):

Sub Macro ()

    For i = 1 to 999999999
       
        Call Doc.StartSampling (15, True, kSMSampleForPeriod)
        Call Doc.SaveAsAdvanced ("C:\Users\test2.adicht", "{FA80FC3E-8409-4053-BEB7-1ACE168EE24F}-0", 4)
        Call Doc.SelectAll ("Chart View")
        Call Doc.Clear ("Chart View")
    Next

End Sub