Board index » delphi » textfiles and arrays to procedures

textfiles and arrays to procedures

Hi,
  I am working on a school program and I am stuck once again. The
problem is I am trying to figure out how to transfer a text file to a
procedure. In the main program the user enters in what text file that
they want to use. Then I have to do a procedure that will display what
is in the text file.  In the procedure I assign the file and reset it.
After that I have a while not end of file loop. In the loop I read in
the file and simply have a writeln followed by the variable I assigned
the text. When I run the program it always breaks at read in the file
name. Now I think I am doing it right by assigning the variable for the
text file as a string and sending it up to the function. I would gladly
appreciate it if anybody can give me suggestions to what I may be doing
wrong. Thank you all.
  sincerely
     M.Grothe

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 

Re:textfiles and arrays to procedures


Quote
Renee Grothe <re...@grothegraphx.com> wrote:
> is in the text file.  In the procedure I assign the file and reset it.
> After that I have a while not end of file loop. In the loop I read in
> the file and simply have a writeln followed by the variable I assigned
> the text. When I run the program it always breaks at read in the file

Okay, you probably have incorrect read and writeln statements.

As an example, suppose I have

var
  f: text;
  filename, data: string;

Then the correct way to access the file is

begin
{...}
  assign(f, filename);
  reset(f);
  while not eof(f) do
    begin
      readln(f, data);
      {...}
      writeln(data);
      {...}
    end;
{...}
end;

where {...} represents any other processing or user interaction you want to
do. It sounds as if you are just using readln(f), or something like that,
which can't work because you don't provide a variable for the data read to
go into.

--
______________________________________________________________________
     The Scarlet Manuka,      |        Nitpickers' Party motto:
  Pratchett Quoter At Large,  |  "He who guards his lips guards his
 First Prophet of Bonni, is:  |  soul, but he who speaks rashly will
   sa...@maths.uwa.edu.au     |    come to ruin." -- Proverbs 13:3
______________________________|_______________________________________

Re:textfiles and arrays to procedures


JRS:  In article <38F28B77.5C1F1...@grothegraphx.com> of Mon, 10 Apr
2000 19:18:32 seen in news:comp.lang.pascal.borland, Renee Grothe

Quote
<re...@grothegraphx.com> wrote:
>  I am working on a school program and I am stuck once again. The
>problem is I am trying to figure out how to transfer a text file to a
>procedure. In the main program the user enters in what text file that
>they want to use. Then I have to do a procedure that will display what
>is in the text file.  In the procedure I assign the file and reset it.
>After that I have a while not end of file loop. In the loop I read in
>the file and simply have a writeln followed by the variable I assigned
>the text. When I run the program it always breaks at read in the file
>name. Now I think I am doing it right by assigning the variable for the
>text file as a string and sending it up to the function. I would gladly
>appreciate it if anybody can give me suggestions to what I may be doing
>wrong. Thank you all.

The problem is that you say it breaks, but do not give details - does
the program loop indefinitely, return to the OS with/without an error
message (and if so which?), or what? - and what is your code?  Clearly
your code is wrong, and if we could see it probably we would be able to
understand your problem.

In addition, you do not describe your system at all.  You should, since
you post here, be using Turbo Pascal 1..7 or BP7; but we get questions
from users of other Pascals, Delphi, and even other languages.  Assuming
TP/BP, then it could be useful to know whether you're running under
plain DOS, or in a Win 3/95/98/NT DOS box, or whatever.  Are you
compiling for DOS, DPMI, or Windows (if you use TP, you may not know,
but it will be DOS)?

You do not say whether you have run-time checks on.  Borland distribute
Pascal with checks off; a programmer who is beginning to learn will put
them on & keep them on.  Alt-O C ...  a learner who has checks off will
be wasting his time and that of everybody he asks.  IMHO, something
about that ought to be in the mFAQ and other FAQs. My Web page
http://www.merlyn.demon.co.uk/pas-norm.htm#Checking refers.

You say the program breaks at "read in the file name" - presumably the
first time this is done.  Therefore all subsequent-in-execution parts of
the program are irrelevant to the problem; in a temporary copy of your
program, get rid of them, and anything earlier that is unrelated to file
name read.  If it now works, you've removed a misunderstanding; seek it.
If the error remains, it will be much easier for you - or us - to see.

If you have the least doubt as to exactly where the "break" occurs, you
may be able to use the de{*word*81}; single-step with (IIRC) F7.

Also, it's easy to add write statements - I tend to add Write(' *1* ');
Write(' *2* '); etc., but anything short and recognisable will do.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Other Threads