07-04-2018 06:20 AM
Hello all,
I have problem in saving the data to the txt./ note pad file
i can save data to the single line but i couldn't able to save data to multiple lines at every run
ex. if i run once it will save in first line of txt file
1. 33
and if i run the program again it will save the data in same line
1. 33
but i need to save as
1. 33
2. 34
3. 35
at every run it should choose next line if data is present at previous line.
VI attached please check and modified
looking forward for your support
Kind regards
vinay
07-04-2018 06:31 AM
You need to use the Set File Position function from File IO>Advanced File functions palette.
Select the "From" input to "End" to append to the file
07-04-2018 09:51 AM
Or open the file once, then without closing it, write to it consecutively. Pass the reference in a shift register. Close when done writing. This way the end position will be remembered and strings will be concatenated.
It depends on your application what's best: sometimes [open\write\close] is better, sometimes open\[write]\close...
07-09-2018 04:21 AM
thanks for replay
I got it by adding read file inside before the write where file will open and data will be written to the next line
regards
vinay
07-09-2018 06:01 AM
What does the while loop do? (Nothing)
What does the for loop do? (Almost nothing)
You can replace the for loop, build array, array to spreadsheet string and concatenate by just a concatenate. The for loop, build array, array to spreadsheet string don't do anything except add a new line to the DATA1 string.
Why use a build array to go from 1D to 2D, and a for loop to go from scalar to 1D? The 2D array is not needed at all, but if you need it, just use two build arrays after each other. Or even better: an Initialize Array.
Now this all could be a placeholder for future work of course, but at the moment you have more redundant code then useful code.
The read will do the trick (set the pointer to the end). But it's a rough way to do it. At some point someone (future you) will think it doesn't do anything and delete it. At least comment why it's there.
With a Set Position, it will be clearer and potentially faster. The read might just really allocate memory and copy the data, you shouldn't depend on a compiler to remove that action...
07-09-2018 06:15 AM
wiebe@CARYA wrote:
The read will do the trick (set the pointer to the end). But it's a rough way to do it. At some point someone (future you) will think it doesn't do anything and delete it. At least comment why it's there.
With a Set Position, it will be clearer and potentially faster. The read might just really allocate memory and copy the data, you shouldn't depend on a compiler to remove that action...
Completely agree here. There is a lot that happens to "Read" a file. Just setting the file position is a lot less work for your application and is more clear what is happening.
07-12-2018 09:58 PM
Hello Crossrulz,
VI is working fine as my requirement and I have done changes like removing the for loop inside and also removing unnecessary blocks and also its working fine
but placing the read option inside the loop it may keep memory like position of file I feel.
please correct me if I am I wrong
Thanks
vinay
07-13-2018 02:10 AM
@Vinaygowda wrote:
but placing the read option inside the loop it may keep memory like position of file I feel.
please correct me if I am I wrong
Yes, it does that. Indeed, it 'works'. Nothing wrong with that argument.
But it does more then you need, it might actually allocate memory, and a file read and data copy. This could become a problem if the file gets large. The read might take more and more time, as the file grows. Definitely not something you should want.
The Set Position on the other hand, has the same effect, but without the cost of the read. And it communicates to others (future you) what it does and why.
You only have to do it once, after opening the file:
Open Set Position For each value Write Close
As reads and writes will also set the position...
And of course the express VI "Write to Measurement File.vi" does this as an option, but I don't really recommend those express VIs, as they tend to need replacement sooner or later.
07-24-2018 03:40 AM
Hello wiebe@CARYA
thanks for replay
the file read and write is small as I need only 10 line i.e ( 1 to 10) / 3 digit number to write to file and after 10 line the file will save and close and the next 10 line is written in new file this is the requirement of project as of now
and its working fine for my application
one more question does it take more processing power to execute or its not a good way to do LabView program
have a nice day
regards
Vinay
07-24-2018 04:02 AM
hi vinaygowda,
opening and closing files is an "expensive" operation.
but since you have the requirement to write to multiple files,
you won't get around that.
a quick note:
replay == play again
reply == answer