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
 All Forums
 Origin Forum
 Origin Forum
 File read write operation problem with 7.5

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 06/21/2004 : 4:42:10 PM
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

3   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 06/22/2004 : 08:43:37 AM
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
peter.cook Posted - 06/22/2004 : 04:07:00 AM
Hi Mike,

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

Cheers,

pete

Mike Buess Posted - 06/21/2004 : 5:22:02 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000