The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 File read write operation problem with 7.5
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 06/21/2004 :  4:42:10 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I've been using some code helpfully supplies by Mike Buess to add a header line to an existing text via an indrect approach using a tmeporary copy.

The code :

%L="add_this_line"; // the line you want to insert
if(exist(C:\origin 6.1\temp.txt)>0) file.remove(C:\Origin 6.1\temp.txt);
file.nlinemode=0; // see discussion in preceding paragraph
fp1=file.open(C:\Origin 6.1\temporary\%U); // open data file for reading
fp2=file.open(C:\origin 6.1\temp.txt,2); // open (create) a file for read/write
file.lwrite(L,fp2); // start new file with the insertion;
// This loop is fine with 6.1 but endless with 7.5!
for(i=1;i>0;)
{
if(file.lread(Z,fp1)==0) break; // read a line from fp1
file.lwrite(Z,fp2); // write it to fp2
};
file.close(fp1);
file.close(fp2);
file -c "C:\origin 6.1\temp.txt" "C:\Origin 6.1\temporary\%U"; // replace data file with new file
file.remove(C:\origin 6.1\temp.txt); // delete temporary file


works fine with 6.1 but, where commented, appears stuck in a loop with 7.5. I'd really appreciate some help/comment thanks.

Cheers,

pete

Mike Buess

USA
3037 Posts

Posted - 06/21/2004 :  5:22:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

I've had similar things occur when I use the wrong line ending mode. Try

file.nlinemode=1; // or 2

That begs the question of why it affects Origin 7.5 but not 6.1, but if it works...

Mike Buess
Origin WebRing Member
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 06/22/2004 :  04:07:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

Thanks for reply....unfortunately changing file.nlinemode to 1 or 2 makes no difference (Origin 7.5 SR3).

Cheers,

pete

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/22/2004 :  08:43:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In Origin 6.1 file.lread() returns 0 when end of file is reached. In Origin 7.5 it returns a missing value (0/0). To make the script work in both versions change the loop to this...

for(i=1;i>0;)
{
n=file.lread(Z,fp1); // read a line from fp1
if(n==0 || n==0/0) break; // quit on EOF
file.lwrite(Z,fp2); // write it to fp2
};

If you've attempted your original script during the current Origin session it's likely that fp1 and/or fp2 are still open and might prevent the new script from working. It might be a good idea to restart Origin before trying it.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/22/2004 08:55:54 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000