LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read line by line from text file using LabWindows/CVI 5.0

Hi
I am trying to read a instruction file too run it. But i don't want to read the whole file and store it in the array insteadi want to read an instruction at a time then execute it and then read the next step instruction. But the problem is my number of instruction parameters on each line vary as per the instruction and it depends on the second parameter in the instruction line i am not ale to read a sigle line and then place the line counter to next line.
Does anyone know about this. I am attaching a sample instruction file.
0 Kudos
Message 1 of 12
(8,113 Views)
Does the line terminate in any control characters (end of line, or new line, carriage return).

You could form a loop to read in chars until this control char is found (remembering to store the file pointer at the end of each line and advance it to the next line by skipping over the control char(s)).

fileptr = 0
commandstring = ""
while ( not at end of file ) <- almost forgot this
{
while ( charFromFile(fileptr++ != 'some control char')
add charFromFile to commandstring

use commandString,
clear commandString
}
add x to fileptr (to skip over control char(s)


Chris
0 Kudos
Message 2 of 12
(8,115 Views)
Give the ReadLine function a try. It should work so long as you have linefeeds at the end of every line. If you don't, then going character by character as suggested by Chris is certainly a viable option.

Ryan K.
NI
0 Kudos
Message 3 of 12
(8,117 Views)
or you could use the readline function I suppose 😞

Or as I do and use a sledge hammer to crack a nut.
It was late honest !!

Chris
0 Kudos
Message 4 of 12
(8,117 Views)
Hey Chris and Ryan,

Thank you for your assistance.
It helped to solve the problem
I am using Readline and then scanning each line to a arrow and then closing the file and storing the step number in a global variable. then execute the instructions and then again follow the same sequence....for reading the line i am using for loop which helps in reading the next line in a sequence using the step number global variable i am hoping it better work.

Aadesh
0 Kudos
Message 5 of 12
(8,117 Views)

Hi,

I want read a particular line in a text file till the end of the line. So what i did is

I used read from text file fn and I gave '-1' to read entire file then I use string subset and gave offset value to tell where I want to start and for the length I dont want to specify how many characters to read instaed I want to give fetch till end of the line. []Can any one tell if u know

 

Thanks in advance

 

--saamy

0 Kudos
Message 6 of 12
(7,162 Views)

Hi saamy,

 

is this question strictly related to the original one? In particular, are you still stuck to CVI5 or are you using a more recent release? If not, I would suggest that you start a new thread instead of appending questions to an old one.

 

With relation to your question, I suggest you to use functions in the Formatting and I/O Library, particularly ReadLine (): using it in a loop till EOF permits you to read the file line-by-line without problems.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 12
(7,159 Views)

What about CopyString (, , "", , ) ?

 

The last parameter Maximum # Bytes specifies the maximum number of bytes, excluding the ASCII NUL, to copy into the target. If you do not want to specify a maximum number of bytes to copy, use –1 for maximum#Bytes.

0 Kudos
Message 8 of 12
(7,156 Views)

sorry Roberto, I know its not related to original one...anyway I will create new thread. Thanks a lot  Roberto Bozzolo

0 Kudos
Message 9 of 12
(7,151 Views)

Hi Wolfgang, I think copystring wont work. I want read a particular line (with start position and till end of the line(single particular line))from a text file which is having so many lines.

0 Kudos
Message 10 of 12
(7,145 Views)