# Importing text file to RAPID

**URL:** <https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759>\
**Category:** RobotStudio\
**Created:** [October 9, 2013, 12:40pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759 "2013-10-09T12:40:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 9, 2013, 12:40pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/1 "2013-10-09T12:40:25Z")

</div>

hello  
i am trying to write and read a txt file into my rapid program, can somebody help me in that it shows no errors but i dont know where it is saved or how it is read by rapid  
this is my code:

ROC write\_to\_file()  
VAR iodev file;  
!Open “HOME:/file.doc”, infile\Read;  
!reg1 := ReadNum(infile);  
VAR num number:= 8;  
Open “Desktop:/SAJJ.TXT”, file \Read;  
Write file, “The number is :”\Num:=number;  
Close file;  
ENDPROC

PROC read\_from\_file()  
VAR iodev file;  
VAR num number;  
VAR string text;  
Open “Desktop:/SAJJ.TXT”, file \Read;  
TPWrite ReadStr(file);  
Rewind file;  
text := ReadStr(file\Delim:=“:”);  
number := ReadNum(file);  
Close file;  
TPWrite text \Num:=number;  
ENDPROC

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 9, 2013, 1:09pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/2 "2013-10-09T13:09:25Z")

</div>

Not sure about “Desktop:/” as a location… Maybe try "C:\FILENAME" to save it to your computer’s C drive running a virtual controller and switch to “HOME:” on a real controller.

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 9, 2013, 6:34pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/3 "2013-10-09T18:34:16Z")

</div>

i don’t have Home , because am doing it now on simulation only does it work ?

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 9, 2013, 6:44pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/4 "2013-10-09T18:44:34Z")

</div>

this line has the error ‘’ C:\FILENAME\SAJJ.TXT", file \Read; "  
Unexpected unknown token.

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 9, 2013, 7:29pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/5 "2013-10-09T19:29:49Z")

</div>

it gives an error for ‘’ : ‘’ and for the dot in ‘’ SAJJ.TXT’’ and for the comma between the file name and the word file  
i put the errors in red maybe it is easier  
C:\FILENAME\SAJJ.TXT", file \Read;

and these are the error :

Syntax error(136): Unexpected ‘:’ 10/9/2013 9:22:58 AM General  
Unexpected unknown token(150): Unexpected unknown token. 10/9/2013 9:22:58 AM General  
Syntax error(137): Expected ‘,’ but found ‘.’ 10/9/2013 9:22:58 AM General  
syntax errors. 10/9/2013 9:22:58 AM RAPID

---

<div class="post-metadata">

**Author:** ![Patient](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Patient](https://tech-community.robotics.abb.com/u/Patient)\
**Post date:** [October 10, 2013, 6:12am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/6 "2013-10-10T06:12:09Z")

</div>

Your code suggests you have the text file in a folder called FILENAME is that true? you are also using \read when you try to write

Open "C:" \file:= “SAJJ.TXT” , file \Write;

---

<div class="post-metadata">

**Author:** ![Patient](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Patient](https://tech-community.robotics.abb.com/u/Patient)\
**Post date:** [October 10, 2013, 6:12am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/7 "2013-10-10T06:12:09Z")

</div>

Do you have your text file located in a folder called ‘FILENAME’ on your C drive? because that is what your code suggests. also I think you want to do a \write instead of a \read. \read means you’re opening your file for reading

try  
Open " C:" \file:= “SAJJ.TXT’” , file \Write;

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 10, 2013, 7:49am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/8 "2013-10-10T07:49:24Z")

</div>

i modified the command  
‘Open “C:\SAJJ.TXT”, file \Write;’  
i got the following error :

Not allowed command 10/10/2013 9:42:48 AM Event Log  
and when i double click on the error explanation it says :

20051: Not allowed command

Description  
The command is only allowed when the client is in control of the resource (program/motion).  
Consequences  
The system remains in the same status, and the requested action will not be performed.  
Actions

1. Check if the client is in control, by checking “Write Access” in RobotStudio.
2. Check if the client who ought to be in control really is.

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 10, 2013, 7:49am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/9 "2013-10-10T07:49:55Z")

</div>

where can i get this write access ?

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 10, 2013, 8:56am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/10 "2013-10-10T08:56:06Z")

</div>

update : the following program gives no errors but does not write anything to the txt file :

PROC write\_to\_file()  
VAR iodev file;  
!Open “HOME:/file.doc”, infile\Read;  
!reg1 := ReadNum(infile);  
VAR num number:= 8;  
Open “C:/file” \file:= “SAJJ.TXT’” , file \Write;  
Write file, “The number is :”\Num:=number;  
Close file;  
ENDPROC

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 10, 2013, 1:17pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/11 "2013-10-10T13:17:33Z")

</div>

VAR string filelocation:=“C:\something2write.txt”;  
VAR string something2write:=“blabla123”;  
VAR iodev file;

PROC pWriteSomething()  
Open filelocation, file \Append;  
Write file, something2write \NoNewLine;  
Close file;  
ENDPROC

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 10, 2013, 7:07pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/12 "2013-10-10T19:07:21Z")

</div>

Hi , thank you so much for your reply, and regarding the code, i would like to tell you what am doing,  
i write this code on rapid only targets with a procedure for thier path then the procedure you provided in the previous comment , i attached the file below, then i press the ‘’ apply ‘’ button in RAPID menu , i got the same errors about ‘’ : ‘’ and ‘’'’ in this line  
VAR string filelocation:= “C\*\*:\*\*something2write.txt”; but when i change it to

**VAR string filelocation:= “C:/something2write.txt”;**

i got no errors but nothing is shown in the txt file .  
please see attached a snapshot for the errors i got in rapid, and for the code  
[write code\_soupUSA modification.txt](https://tech-community.robotics.abb.com/uploads/short-url/grbTeURn9RMd7Ct41WMxB3GlxMY.txt) (974 Bytes)

 ![snapshot for the code in RS rapid.PNG](https://europe1.discourse-cdn.com/flex005/uploads/robotics1/original/2X/a/ae3ea5ed152bb1f2ef227e9005e2dcf5cc7843fc.png)

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 10, 2013, 8:00pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/13 "2013-10-10T20:00:18Z")

</div>

Hummm. Try creating a folder called “temp” on the C: drive and then change “C:/something2write.txt” to “C:/temp/something2write.txt” and see if it works.

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 10, 2013, 8:17pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/14 "2013-10-10T20:17:43Z")

</div>

Also, you do have a HOME file eventhough you are running a VC.

The easiest way to find it is to:

1. click on the [Controller] tab in RobotStudio
2. right-click on the Current Station name in the left Controller window
3. choose Open System Folder

Change to: VAR string filelocation:= “HOME:something2write.txt”;  
and it should show in your HOME folder instead of your C: drive.

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 10, 2013, 8:35pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/15 "2013-10-10T20:35:44Z")

</div>

Just tried the code below and it worked:

!VAR string filelocation:=“C:/temp/something2write.txt”;  
VAR string filelocation:=“HOME:something2write.txt”;  
VAR string something2write:=“blabla123”;  
VAR iodev file;

PROC pWriteSomething()  
Open filelocation, file \Append;  
Write file, something2write \NoNewLine;  
Close file;  
ENDPROC

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 11, 2013, 7:39am UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/16 "2013-10-11T07:39:27Z")

</div>

Hello, i found the Home thanks alot, and thanks for your patience but i created the txt file in the Home, but still not writing, shall i press something more than apply, i tried also to press synchronize to VC and synchronize to station , but still empty ☹

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 11, 2013, 2:15pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/17 "2013-10-11T14:15:53Z")

</div>

[Apply] saves your changes but doesn’t run the program. Do you know if you’ve been able to run any other code on your virtual controller?

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 11, 2013, 5:26pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/18 "2013-10-11T17:26:34Z")

</div>

usually when i make changes in my rapid program, in the beginning i apply changes , then i press [synchronize to station]

---

<div class="post-metadata">

**Author:** ![Engineer345](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Engineer345](https://tech-community.robotics.abb.com/u/Engineer345)\
**Post date:** [October 11, 2013, 5:28pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/19 "2013-10-11T17:28:47Z")

</div>

but if i have targets and path, i make [synchronize to VC] then i can use them in the rapid program, that is what i know ☹

---

<div class="post-metadata">

**Author:** ![soup](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/soup/32/1592_2.png) [@soup](https://tech-community.robotics.abb.com/u/soup)\
**Post date:** [October 11, 2013, 6:54pm UTC](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759/20 "2013-10-11T18:54:05Z")

</div>

Demo of creating a simple station to run some RAPID:

> **[Build effective training for the AI era with Articulate 360 | Articulate](https://www.articulate.com/)**
>
> Empower every team to transform knowledge into custom online training with the #1 AI-powered platform for workplace learning.

Demo of writing to a text file using the code above:

> **[Build effective training for the AI era with Articulate 360 | Articulate](https://www.articulate.com/)**
>
> Empower every team to transform knowledge into custom online training with the #1 AI-powered platform for workplace learning.

[Next page](https://tech-community.robotics.abb.com/t/importing-text-file-to-rapid/5759.md?page=2)
