# CSV Export

This function block facilitates the logging and export of data into a CSV file format. It allows users to specify the file path, file name, and conditions for starting the logging process and exporting the data.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Folder Path` The directory where the CSV file will be saved.

`File Name` The name of the CSV file to be created.

`Start Logging` A boolean that, when set to true, begins logging the incoming data.

`Export File` A boolean that triggers the export of logged data to the specified CSV file.

`Data_{i}` Up to ten generic data inputs. Each can receive data that you want to log into the CSV file.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

This function block does not produce any outputs.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Set Data Headers` Users can enter custom headers for each data input field to label them appropriately in the CSV file.

## 🎨 Features <a href="#features" id="features"></a>

`Dynamic Logging` Effectively logs data in real-time when the start logging condition is met.

`Automatic Header Management` Automatically creates or updates headers in the CSV file based on the user-defined headers.

`Error Handling` Comprehensive error messaging helps users troubleshoot issues related to file permissions or read/write operations.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. **Specify Folder and File Name**: Connect the `Folder Path` and `File Name` inputs to determine where and how the CSV file will be saved.
2. **Configure Headers**: Enter the desired headers for your data fields in the header text boxes.
3. **Start Logging**: Send a `true` value to the `Start Logging` input to begin capturing data.
4. **Export Data**: To export the logged data to CSV format, send a `true` value to the `Export File` input.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When the conditions are met, this function block logs the incoming data along with the specified headers into the chosen CSV file. It handles the creation of a new file or updates an existing one, maintaining data integrity.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

<details>

<summary>Setting Up File Paths</summary>

To avoid errors, it’s helpful to always check that the provided folder path exists prior to exporting. You can use folders that are readily accessible, like your desktop or a designated documents folder.

</details>

<details>

<summary>Managing Data Headers</summary>

Make sure to create meaningful headers that accurately describe the data being logged to make the CSV file more understandable and useful.

</details>

<details>

<summary>Frequent File Access</summary>

If you frequently access the CSV file, ensure that it is closed in any spreadsheet software before running the export function to prevent access issues.

</details>

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

<details>

<summary>CSV File Not Exporting</summary>

If the CSV file doesn’t export, check for the following:

* Permissions: Ensure that the directory is writable and that you have permission to create or modify files in that location.
* Active Microsoft Excel files: If the file is currently open in Excel or any other program, close it before exporting.

</details>

<details>

<summary>No Data Logged to Export</summary>

If you receive a warning about no stored data to export, ensure that the `Start Logging` input has been activated and that there are actual inputs connected.

</details>
