Solved

Should I put the A:

Posted on 2000-03-08
9
155 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
printers log data 3 358
Suppress UAC Prompt using shellapi 6 484
Delphi Thead Pool or (only run last procedure called) 13 806
Activex loadlibrary and show parented form issue 6 308
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

18 Experts available now in Live!

Get 1:1 Help Now