Solved

Should I put the A:

Posted on 2000-03-08
9
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 49

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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 49

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 49

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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