Jump to content

A 'file-read' question...


Recommended Posts

I'm trying to build a procedure that will read an array of 'real' values from a prepared ASCII file and then do some drawing based on those values. Initially, I got hung up with syntax errors but eventually got an experimental procedure that would sort of read the supplied data file.

The problem I have is VS does not seem to reset the record-marker to BOF. It reported, as I recall, the final three values out of a set of 16. I decided to build a test-procedure that allowed VS to write its own file and then read it. That script is pasted in below. The supplied procedure, 'A_test', reads the last value OK, but reports zeros for the other seven.

Does anyone have any idea how to overcome this mode of operation?==================================================PROCEDURE A_test;VAR a1,a2,a3,a4,a5,a6,a7,a8 :REAL; b1,b2,b3,b4,b5,b6,b7,b8 :REAL; filespec : STRING;BEGIN a1 := 1.1; a2 := 2.2; a3 := 3.3; a4 := 4.4; a5 := 5.5; a6 := 6.6; a7 := 7.7; a8 := 8.8; PutFile('What file?','The output',filespec); IF NOT DidCancel THEN BEGIN WriteLn(a1); WriteLn(a2); WriteLn(a3); WriteLn(a4); WriteLn(a5); WriteLn(a6); WriteLn(a7); WriteLn(a8); Close(filespec); END;{file-write} Open(filespec); WHILE NOT EOF(filespec) DO ReadLn(b1); ReadLn(b2); ReadLn(b3); ReadLn(b4); ReadLn(b5); ReadLn(b6); ReadLn(b7); ReadLn(b8); Close(filespec);Message(b1,' ',b2,' ',b3,' ',b4);Wait(5);Message(b5,' ',b6,' ',b7,' ',b8);END;RUN(A_test);==================================================I notice that Pascal has a 'RESET' instruction that moves the marker to BOF, but I don't see that option in VS!

I'll be grateful for any advice on this issue. TIA.

Link to comment

Gordon, Here's a quick modification of your scriptto show reading each line. VS automaticallyresets and starts at the BOF for you.HTHDave

PROCEDURE A_test;CONSTfilespec ='The output';VARa1,a2,a3,a4,a5,a6,a7,a8 :REAL;b1,b2,b3,b4,b5,b6,b7,b8 :REAL;

BEGINa1 := 1.1;a2 := 2.2;a3 := 3.3;a4 := 4.4;a5 := 5.5;a6 := 6.6;a7 := 7.7;a8 := 8.8;Rewrite(filespec);WriteLn(a1);WriteLn(a2);WriteLn(a3);WriteLn(a4);WriteLn(a5);WriteLn(a6);WriteLn(a7);WriteLn(a8);Close(filespec);

Open(filespec);WHILE NOT EOF(filespec) DOBEGIN StdRead(b1,b2,b3,b4,b5,b6,b7,b8); Close(filespec); Message(b1,' ',b2,' ',b3,' ',b4,' ',b5,' ',b6,' ',b7,' ',b8); Wait (3); Clrmessage;END;END;RUN(A_test);

[ 04-22-2002: Message edited by: Fuge ]

Link to comment

Thanks a bunch Dave, for the quick and effective reply.

I had eyeballed the 'Rewrite' and 'StdRead' procedures a number of times, but could not get a clue from the written material as to what they might do for me! From what was said, it appeared they would not be beneficial, so I never tried them.

I appreciate the education.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...