Solved

Should I put the A:

Posted on 2000-03-08
9
153 Views
Last Modified: 2010-04-16
Here's is my program:

var name: string;
      wage : real;
      years : integer;
      fileA, fileB: text;

begin
assign (fileA, 'salary.dat');
assign (fileB, 'salary2.dat');
reset (fileA);
rewrite (fileB);
while not seekeof (fileA) do
begin {while}
     readln (fileA, name);
    readln (fileA, wage);
    readln (fileA, years);
years := years + 1;
       if years >= 10 then
             wage := wage + 30
       else wage := wage + 15
writeln (fileB, name);
writeln (fileB, wage);
writeln (fileB, years);
end;{while}
close (fileA);
close (fileB)
end.

If I do this: assign (fileA, 'A:salary.dat');
                   assign (fileB, 'A:salary2.dat');

I get a runtime error, however, if I don't put the A: then I get a message saying it can't fileA.

P.S. Do I need to make a file for salary2.dat or does TP do that anyway?
0
Comment
Question by:kazooie21
  • 5
  • 3
9 Comments
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599535
when you put 'A:' program tries to open existing file on A drive
if you use onle 'salary.dat' name program tries to open that file in current drive and current directory. if you use 'reset()' this means that file MUST exist, so make a sample file first, put it somewhere and use this particular path+filename in 'assign' call
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599541
for 'salary2' which is assigned to fileB in your example you use 'rewrite' and this procedure creates new file ALWAYS, even if file exists it OVEWRITTEN again
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2599558
Go as per Alisher_N

might need assign(fileA, 'A:\salary.dat');

Assuming that salary.dat is not inside any folder in A: - for example it is not inside A:\wages

Your floppy disk needs to be in A: when you run the program and salary.dat needs to be on the disk.  Disk also needs to be NOT write protected.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599733
to dbrunton:

why NOT write protected ? if we're talking about first file
assign( fileA, 'a:\salary.dat' );

he tries only read it, so it will work for any floppy disk... second file fileB of course must be available for write
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:dbrunton
ID: 2599780
Alisher_N

Correct.  He's getting disk errors.  By making sure the disk is NOT write protected we eliminate one possible source.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599809
we don't know actually where are his files and which ones on floppy or no ;-)...
0
 

Author Comment

by:kazooie21
ID: 2602885
Ok, I did that and the program runs. I opened up the salary2.dat file and found this for the wage:

103000000000+E04 (That's not exact, but they were in that format).

I declared the wage as real. What's the deal?
0
 
LVL 48

Accepted Solution

by:
dbrunton earned 5 total points
ID: 2603617
If you declared wages as real this what you will get.  You are looking at an exponent this is the +E04.  There is nothing wrong in what you have got, it is saving it correctly.

Try using integer or longint for your variable type if you want to see something more understandable.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2603762
if you want to output a real vaule in more convenient way you can use
writeln( myfile, X:8:2 );
where 8 - total number of digits
      2 - after decimal point

but are you going to browse that file manually ? if not it doesn't matter - when you read it back your program will get proper value...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now