1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. Fanuc Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

reading new line in .txt file

  • jagroop77
  • May 11, 2015 at 2:03 PM
  • Thread is Resolved
  • jagroop77
    Trophies
    3
    Posts
    168
    • May 11, 2015 at 2:03 PM
    • #1

    Hi,
    We are trying to read the data from .txt file with karel program.
    at the moment karel program is reading the data from file is the data is seprated by comma or tab .
    But it is not reading the data if the data is written in new line.
    example
    201,303,404..................is working
    201,
    303,
    404
    ...............is not working.

    can someone help me that how to jump to next line to read the data

    Thanks

    Rupy

  • gwallee
    Trophies
    3
    Posts
    41
    • May 11, 2015 at 11:45 PM
    • #2

    Are you calling the "READ" command more than once? Each time it is called, a new line is read/

  • urdemiul
    Trophies
    3
    Posts
    26
    • May 11, 2015 at 11:51 PM
    • #3

    Hi rupy,

    best way to do it is with one example. My *.txt file is reading an integer and two strings as you can see:

    1002 'Description' 'Comment'
    1003 'Description' 'Comment'

    So the statement READ in the program looks like this:

    REPEAT
    READ Readfile (Num,Descrip::0::2,Coment::0::2)
    ....
    UNTIL STATUS<>0

    Using the loop allows to read the next line until a new end of line is found. As you can see there are no tabs only spaces and remember to do the formatting of the data you want to read in order to extract the content from the *.txt file.

  • jagroop77
    Trophies
    3
    Posts
    168
    • May 12, 2015 at 6:38 AM
    • #4

    Hi,
    thanks for your help.it is working .
    I have used the read command one more time and it is working

    thanks
    Rupy

  • dha
    Reactions Received
    28
    Trophies
    6
    Posts
    397
    • February 16, 2016 at 11:01 AM
    • #5

    I'm having trouble reading txt file.

    I need to read only the first line of text file. I'm getting error 2021 if line is shorter or longer than 10 characters.

    Code
    PROGRAM READER
    	%NOLOCKGROUP
    
    
    VAR
    	f_file		: FILE
    	s_code		: STRING[10]
    	i_code		: INTEGER
    	STATUS	: INTEGER
    
    
    
    
    BEGIN
    	s_code = ''
    	i_code = 0
    
    	--SET_FILE_ATR (f_file, ATR_UF)
    
    
    	-- Opening file
    	WRITE ('', CR)
    	WRITE ('', CR)
    	WRITE ('Opening ...', CR)
    	OPEN FILE f_file ('ro', 'MC:test.txt')
    	STATUS = IO_STATUS (f_file)
    	IF STATUS <> 0 THEN
    		WRITE ('Open status: ', STATUS, CR)
    	ENDIF
    
    
    	-- Writing to file
    	--WRITE f_datoteka ('This is line 1', CR)
    
    
    	-- Reading from file
    	WRITE ('Reading ...', CR)
    	READ f_file (s_code::10) 
    	--READ f_file (i_code) 
    
    	STATUS = IO_STATUS (f_file)
    	IF STATUS <> 0 THEN
    		WRITE ('Read status: ', STATUS, CR)
    	ENDIF
    
    
    	-- Writing code
    	WRITE ('Code: ', s_code, CR)
    	--WRITE ('Code: ', i_code, CR)
    
    	CLOSE FILE f_file
    
    
    END READER
    Display More

    Even if I use READ f_file (s_code) instead of READ f_file (s_code::10) I'm getting an error: Uninitialised data used ...

    As I understand manual, READ should return string even if it is shorter than specified and truncate if it is longer...

    What am I doing wrong?

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download