# How to create a .csv file

**URL:** <https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220>\
**Category:** RobotStudio\
**Created:** [July 9, 2014, 7:45am UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220 "2014-07-09T07:45:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pivix](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@Pivix](https://tech-community.robotics.abb.com/u/Pivix)\
**Post date:** [July 9, 2014, 7:45am UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/1 "2014-07-09T07:45:49Z")

</div>

Hello to all of you,  
I’m new to ABB RAPID programming and this is my first post on this forum.

I am working on a program that should write a report file in .csv format, my question is: how is possible to change line between one “write” instruction and the next?  
The following is the code I wrote:

VAR string ORA;  
VAR string DATA;  
VAR iodev MY\_FILE;  
VAR num zero:=1000;  
VAR num K:=289;  
VAR num app\_calc:=0;  
VAR num app\_ch\_mm:=0;  
VAR num app\_mm\_abs:=0;  
DATA:=CDate();  
ORA:=CTime();  
app\_calc:=ANALOGIC\_1-zero;  
app\_ch\_mm:=app\_calc/K;  
app\_ch\_mm:= Round(app\_ch\_mm\Dec:=0);  
TEST N\_Point  
CASE 01:  
TPErase;  
Open “HOME:”, \File:=“Measure.csv”, MY\_FILE;  
Write MY\_FILE, “CONTRÔLE BROCHES: RAPPORT DES VALEURS MESURÉ”;  
Write MY\_FILE, "Date: “+DATA+”,Heure: "+ORA;  
Write MY\_FILE, “Trou N.,Nom de la variable,Valeur mesurée”;  
Close MY\_FILE;  
Ctrl\_Pin\_KO:=FALSE;  
setgo REG\_01, app\_ch\_mm;  
IF app\_ch\_mmMax THEN  
Ctrl\_Pin\_KO:=TRUE;  
SetDO REJECT\_PIN\_CTRL, 1;  
ENDIF  
Open “HOME:”, \File:=“Measure.csv”, MY\_FILE\Append;  
Write MY\_FILE, “01,REG\_01,” \Num:=app\_ch\_mm;  
Close MY\_FILE;  
TPWrite “REG\_01=”\Num:=app\_ch\_mm;

CASE 02:  
setgo REG\_02, app\_ch\_mm;  
IF app\_ch\_mmMax THEN  
Ctrl\_Pin\_KO:=TRUE;  
SetDO REJECT\_PIN\_CTRL, 1;  
ENDIF  
Open “HOME:”, \File:=“Measure.csv”, MY\_FILE\Append;  
Write MY\_FILE, “02,REG\_02,” \Num:=app\_ch\_mm;  
Close MY\_FILE;  
TPWrite “REG\_02=”\Num:=app\_ch\_mm;  
…  
…  
…  
ENDTEST

Thanks for any tips you will give to me

---

<div class="post-metadata">

**Author:** ![Micky](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Micky](https://tech-community.robotics.abb.com/u/Micky)\
**Post date:** [July 9, 2014, 12:45pm UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/2 "2014-07-09T12:45:16Z")

</div>

Hi,

I am not sure if I understand your problem, but if you want to write several data into the same line, you can use the optional parameter “\*_NoNewLine_\*” of the instruction “Write”.

In this case the line feed character that normally indicates the end of the text is omitted.

You have to reuse this argument **NoNewLine** as long as you will add no line break .

**Example:**

Write myFile,“Value1 ;”\num:=nValue1\NoNewLine;

Write myFile,“Value2 ;”\num:=nValue2\NoNewLine;

Write myFile,“Value3 ;”\num:=nValue3;

The three values will be written into the same line of your text file.

Best regards

Micky

---

<div class="post-metadata">

**Author:** ![Pivix](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@Pivix](https://tech-community.robotics.abb.com/u/Pivix)\
**Post date:** [July 16, 2014, 9:49am UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/3 "2014-07-16T09:49:08Z")

</div>

Hi Micky,  
thanks for your reply.  
My problem is exactly the opposite: what should I do to write a new line every time I put new data into my file?

With the option “\NoNewLine” I write all the data on a single line.  
Without this option I was thinking that there is some difference but… when I open the file using the Notepad in Windows7 I can’t see any kind of change ☹

---

<div class="post-metadata">

**Author:** ![Klaus](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@Klaus](https://tech-community.robotics.abb.com/u/Klaus)\
**Post date:** [July 29, 2014, 12:04pm UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/4 "2014-07-29T12:04:49Z")

</div>

Hi.

Use wordpad insteed.

BR Klaus

---

<div class="post-metadata">

**Author:** ![Neily03](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@Neily03](https://tech-community.robotics.abb.com/u/Neily03)\
**Post date:** [July 30, 2014, 11:22am UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/5 "2014-07-30T11:22:01Z")

</div>

Like Klaus said use Wordpad or even Word, Notepad will display everything one line, we had the same problem here, thought we were going mad!

---

<div class="post-metadata">

**Author:** ![S\_Smith](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/s_smith/32/713_2.png) [@S\_Smith](https://tech-community.robotics.abb.com/u/S_Smith)\
**Post date:** [August 16, 2019, 5:36pm UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/6 "2019-08-16T17:36:41Z")

</div>

\Append; will start a new line

Here in an example…

PROC RECORD\_THINGS()

VAR string stDirNetwork\_Parts:=“pc:/asdf/Parts/”;  
VAR string stDirNetwork\_Logs:=“pc:/asdf/Logs/”;  
VAR iodev ioCVB\_LOG;  
VAR iodev ioCVB\_READ;  
VAR num A\_number;  
VAR num This\_Cycle;  
VAR num lineCounter := 0;

VAR string FILE\_WORDS;  
VAR string LOG\_RECORD;  
VAR string This\_Average;  
VAR string whichLOG := “123456.csv”;

!!! RECORD ALL OF THE THINGS !!!

Open stDirNetwork\_Logs\File:= WhichLog, ioPPFP\_LOG\Append;

Write ioPPFP\_LOG, What\_Part + “,” + CDATE()+“,” + CTime() +“,” + This\_Average +“,”\NoNewLine;  
Write ioPPFP\_LOG, “,” + "Machine Total = " \num:=Machine\_Count;

Close ioPPFP\_LOG;

!!! DONE RECORDING ALL OF THE THINGS !!!

ENDPROC

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [August 18, 2019, 9:23am UTC](https://tech-community.robotics.abb.com/t/how-to-create-a-csv-file/6220/7 "2019-08-18T09:23:11Z")

</div>

Hello,  
RAPID use Unix End Of Line ASCII 10 (LF) while Windows use 13 + 10 (CR LF) and MAC 13 (CR).  
You can install Noteped++ to edit your files. It’s free and open source.  
If you really want to have Windows EOL, you can do it like this:

```auto

VAR num eol{2}:=[13,10];
...

  Write ioPPFP_LOG, "Your text here"\NoNewLine;
  WriteBin ioPPFP_LOG, eol, 2;

...

```

Or

```auto

VAR string sEOL;

...
  sEOL:=ByteToStr(13\Char)+ByteToStr(10\Char);;

  Write ioPPFP_LOG, "Your text here" + sEOL\NoNewLine;
...

```
