Can anyone help me? 
Author Message
 Can anyone help me?

I am having a terrible time with a Pascal program that I am writing that
needs to call a dat file. I can't get it to call but the first line and I
have looked this over for 2 days and can't figure it out. If anyone can help
me, please email me back. Thanks so much

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.*-*-*.com/ ).
Version: 6.0.417 / Virus Database: 233 - Release Date: 11/8/02



Fri, 27 May 2005 04:04:04 GMT  
 Can anyone help me?
On Sun, 8 Dec 2002 14:04:04 -0600, "Rhonda Sellers"

Quote:

>I am having a terrible time with a Pascal program that I am writing that
>needs to call a dat file. I can't get it to call but the first line and I
>have looked this over for 2 days and can't figure it out. If anyone can help
>me, please email me back. Thanks so much

Let's see the VAR declaration of dat file type and anything else you
think would help us to figure out the problem.


Fri, 27 May 2005 06:00:01 GMT  
 Can anyone help me?
I'm using Turbo Pascal version 1.5 and this is turning out to be a really
long program but I don't think that it really needs to be this long, I could
be mistaken but because I'm really new to this. I'm trying to learn it but
it seems to be a really tough language. QBasic was so easy compared to this.

Thanks so much,
Rhonda

program gradefile;
uses wincrt;

var
standing:STRING;
fname:STRING;         {FIRST NaMe OF STUDeNT}
lname:STRING;         {LaST NaMe OF STUDeNT}
lgrade:char;         {LeTTeR GRaDe OF STUDeNT}
hc:integer;          {HOURS cReDITeD FOR cLaSS}
MYDATA:text;          {THe FILe TO USe THe TeXTFILe ON THIS DISK}
sid:char;
name:char;
sep:char;
grade:char;
hr:char;
hrs:integer;
point:integer;
totpoints:real;
counter:integer;
gp:real;
stuid:string;
ct:integer;
ctt:integer;
sep2:STRING;
name2:char;
totalhours:integer;
thr:integer;
counter2:real;
nextchar:char;
hours:integer;
pointsearned:integer;
totalpointsearned:real;

procedure getgrades;

begin
totpoints:=0;
counter2:=0;
counter:=0;
totalhours:=0;

While counter <> 9 DO
begin
ReaD (MYDATA,SID);
STUID:=STUID+SID;
counter:=counter + 1;
end;

while name<>' ' DO
begin
read(MYDATA,Name);
fname:=fname + name;
end;

while name2<>' 'do
begin
read (MYDATA,Name2);
lname:=lname + Name2;
end;

while sep=' ' do
begin
read(MYDATA, sep);
sep2:=sep2 + sep;
end;

read(MYDATA,ct);
ctt:=ctt+ct;

counter2:=ctt;
writeLn (counter2);
While counter2 > 0 Do
begin
counter2 := counter2 - 1;
read (MYDATA, nextchar);
grade:=nextchar;

case grade OF
'a' : POINT := 4;
'b' : POINT := 3;
'c' : POINT := 2;
'd' : POINT := 1;

else
POINT := 0;
end;

TOTPOINTS:= TOTPOINTS+POINT;
grade:=' ';
read(mydata,nextchar);
hr:=nextchar;

case hr of
'1':hours:=1;
'2':hours:=2;
'3':hours:=3;
'4':hours:=4;
'5':hours:=5;

else
hours:=0;
end;

pointsearned:=point*hours;
totalpointsearned:=totalpointsearned+pointsearned;
totalhours:=totalhours+hours;
hr:=' ';
pointsearned:=0;
end;

case totalhours OF
1,2,3,4,5,6,7,8,9:standing:='freshman';
10,11,12,13,14,15,16,17:standing:='sophmore';
18,19,20,21,22,23,24:standing:='junior';
else
standing:='senior';
end;

gpa:= TOTPOINTS / counter2;
writeln;
writeln;
writeln(stuid:9,' ',lname,' ',fname,' ',ctt,'
',totpoints:3:2,'',totalhours:3,' ',gpa:2:1,' ',standing);
end;

begin

ASSIGN(MYDATA,'A:\GRD.DAT');
RESET(MYDATA);
WHILE NOT EOF (MYDATA) DO
getgrades;
close(mydata);

end.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.417 / Virus Database: 233 - Release Date: 11/8/02



Fri, 27 May 2005 07:37:41 GMT  
 Can anyone help me?

As you have at least tried to do your homework yourself, you deserve
a response. I do recommend that you have a long chat with your teacher.
He/she is paid to do just that. Asking all the necessary questions
shouldn't affect your grade (not too much at least).

First a few general comments:

1) Learn to indent your code. This is a relatively short snippet, so it
   is still mostly readable, but you are about to reach the point, where
   that will change...

2) Why do you declare all your variables as global, when most of them
   are only used in the subroutine? Is this a bad habit coming from
   using QuickBasic? It is actually the cause of many of your problems.

3) If your program seems to work ok for the first input, but fails
   at the second, there are grounds for suspecting an uninitialized
   variable.

4) Give the exact error message you get (BP gives those nice run-time
   error numbers for a good reason).

Quote:
> program gradefile;
> uses wincrt;

> var
> standing:STRING;
> fname:STRING;         {FIRST NaMe OF STUDeNT}
> lname:STRING;         {LaST NaMe OF STUDeNT}
> lgrade:char;         {LeTTeR GRaDe OF STUDeNT}
> hc:integer;          {HOURS cReDITeD FOR cLaSS}
> MYDATA:text;          {THe FILe TO USe THe TeXTFILe ON THIS DISK}
> sid:char;
> name:char;
> sep:char;
> grade:char;
> hr:char;
> hrs:integer;
> point:integer;
> totpoints:real;
> counter:integer;
> gp:real;
> stuid:string;
> ct:integer;
> ctt:integer;
> sep2:STRING;
> name2:char;
> totalhours:integer;
> thr:integer;
> counter2:real;
> nextchar:char;
> hours:integer;
> pointsearned:integer;
> totalpointsearned:real;

Huh! What are all these vars supposed to do?  I would use a record
to keep the data related to a single student clumped together,
but suit yourself.

Quote:

> procedure getgrades;

no local vars!!!!!!???????????

Quote:
> begin
> totpoints:=0;
> counter2:=0;
> counter:=0;
> totalhours:=0;

> While counter <> 9 DO
> begin
> ReaD (MYDATA,SID);
> STUID:=STUID+SID;
> counter:=counter + 1;
> end;

[snipped a few other similar blocks to improve the "new text/old text" -ratio]

Do we really want to read strings this way? Ok, I see you want
to have the student id and the names on the same line, but I would
use the built-in string handling procedures to do this.
After all, somebody may accidentally insert two blanks between the
id and the name. Also, why didn't you initialize the id and the
names to the empty string. Right now the name of the second student
will contain the name of the first student as well?

Mind you, unless otherwise dictated by your teacher, I would use
different formatting of the input file (you have complete control
of this!) and simply put the student id on one line, the first name
on the next and then the family name. This is because then I could
read all of them with a simple readln-command and be done with it.

It is, of course, useful to learn to parse an input line containg
many separate fields, but the more urgent problem of getting the
logic of the program right should get a higher priority.

Quote:

> read(MYDATA,ct);
> ctt:=ctt+ct;

what are the variables 'ctt' and 'ct' supposed to do?
My wild guess is that they have something to do with the
number of courses a particular student has taken. If that is
the case, then some initialization is missing.

No, that guess was incorrect. 'ctt' must be the number of courses
taken by all the students altogether. That does make the following
loop VERY suspicious. (why is counter2 given the value ctt rather
than ct?)

- Show quoted text -

Quote:

> counter2:=ctt;
> writeLn (counter2);
> While counter2 > 0 Do
> begin
> counter2 := counter2 - 1;
> read (MYDATA, nextchar);
> grade:=nextchar;

> case grade OF
> 'a' : POINT := 4;
> 'b' : POINT := 3;
> 'c' : POINT := 2;
> 'd' : POINT := 1;

> else
> POINT := 0;
> end;

> TOTPOINTS:= TOTPOINTS+POINT;
> grade:=' ';
> read(mydata,nextchar);
> hr:=nextchar;

> case hr of
> '1':hours:=1;
> '2':hours:=2;
> '3':hours:=3;
> '4':hours:=4;
> '5':hours:=5;

> else
> hours:=0;
> end;

> pointsearned:=point*hours;
> totalpointsearned:=totalpointsearned+pointsearned;
> totalhours:=totalhours+hours;
> hr:=' ';
> pointsearned:=0;
> end;

It would be nice to know (without having to examine more closely)
that your loop ends here. That is why you should indent your code.

[snipped the output section that seemed to be mostly ok]

Ok. So at this point we are supposed to have handled a single
student. Time to re-cap. Is the input file ready for another
round? No. Remember that you were reading the grades/hours
one character at a time. Thus the text file pointer is (most likely)
at the end of the line containing the data related to this student.

This means that the student id of the next student will begin
with a carriage return and a line-feed (or was it the reverse order?),
his/her first name will be the first name of the previous student
appended by the two last characters of his/her id etc.

Quote:
> end;

[snipped the main program that only uses a single variable 'mydata'
My style is that variables used by the main program are (more or less)
the only variables declared in the main VAR-section. There are various
good reasons for diverting from this rule, but none apply here.]

Hopefully this will get you started (the list of potential problems
most likely isn't complete). The best single advice I can give to you
is to learn to use the de{*filter*}: simply by tracing the code one line
at a time and watching the key variables suddenly get some unexpected
values, will pinpoint you most (if not all) of the above errors.

I don't know Quickbasic, but I don't think your difficulties have
anything to do with Pascal.

Good luck,

Jyrki Lahtonen, Turku, Finland



Fri, 27 May 2005 16:58:15 GMT  
 Can anyone help me?
Thank you so much Jyrki, you have been a tremendous help. I'm surprised I
didn't stick any Qbasic commands in there as well. I'm terrible for doing
that.
I am going to rewrite this and try to fix all of my mistakes. Again, thank
you so very much for all your help.

Sincerely,
Rhonda Sellers


Quote:


> As you have at least tried to do your homework yourself, you deserve
> a response. I do recommend that you have a long chat with your teacher.
> He/she is paid to do just that. Asking all the necessary questions
> shouldn't affect your grade (not too much at least).

> First a few general comments:

> 1) Learn to indent your code. This is a relatively short snippet, so it
>    is still mostly readable, but you are about to reach the point, where
>    that will change...

> 2) Why do you declare all your variables as global, when most of them
>    are only used in the subroutine? Is this a bad habit coming from
>    using QuickBasic? It is actually the cause of many of your problems.

> 3) If your program seems to work ok for the first input, but fails
>    at the second, there are grounds for suspecting an uninitialized
>    variable.

> 4) Give the exact error message you get (BP gives those nice run-time
>    error numbers for a good reason).

> > program gradefile;
> > uses wincrt;

> > var
> > standing:STRING;
> > fname:STRING;         {FIRST NaMe OF STUDeNT}
> > lname:STRING;         {LaST NaMe OF STUDeNT}
> > lgrade:char;         {LeTTeR GRaDe OF STUDeNT}
> > hc:integer;          {HOURS cReDITeD FOR cLaSS}
> > MYDATA:text;          {THe FILe TO USe THe TeXTFILe ON THIS DISK}
> > sid:char;
> > name:char;
> > sep:char;
> > grade:char;
> > hr:char;
> > hrs:integer;
> > point:integer;
> > totpoints:real;
> > counter:integer;
> > gp:real;
> > stuid:string;
> > ct:integer;
> > ctt:integer;
> > sep2:STRING;
> > name2:char;
> > totalhours:integer;
> > thr:integer;
> > counter2:real;
> > nextchar:char;
> > hours:integer;
> > pointsearned:integer;
> > totalpointsearned:real;

> Huh! What are all these vars supposed to do?  I would use a record
> to keep the data related to a single student clumped together,
> but suit yourself.

> > procedure getgrades;

> no local vars!!!!!!???????????

> > begin
> > totpoints:=0;
> > counter2:=0;
> > counter:=0;
> > totalhours:=0;

> > While counter <> 9 DO
> > begin
> > ReaD (MYDATA,SID);
> > STUID:=STUID+SID;
> > counter:=counter + 1;
> > end;
> [snipped a few other similar blocks to improve the "new text/old
text" -ratio]

> Do we really want to read strings this way? Ok, I see you want
> to have the student id and the names on the same line, but I would
> use the built-in string handling procedures to do this.
> After all, somebody may accidentally insert two blanks between the
> id and the name. Also, why didn't you initialize the id and the
> names to the empty string. Right now the name of the second student
> will contain the name of the first student as well?

> Mind you, unless otherwise dictated by your teacher, I would use
> different formatting of the input file (you have complete control
> of this!) and simply put the student id on one line, the first name
> on the next and then the family name. This is because then I could
> read all of them with a simple readln-command and be done with it.

> It is, of course, useful to learn to parse an input line containg
> many separate fields, but the more urgent problem of getting the
> logic of the program right should get a higher priority.

> > read(MYDATA,ct);
> > ctt:=ctt+ct;

> what are the variables 'ctt' and 'ct' supposed to do?
> My wild guess is that they have something to do with the
> number of courses a particular student has taken. If that is
> the case, then some initialization is missing.

> No, that guess was incorrect. 'ctt' must be the number of courses
> taken by all the students altogether. That does make the following
> loop VERY suspicious. (why is counter2 given the value ctt rather
> than ct?)

> > counter2:=ctt;
> > writeLn (counter2);
> > While counter2 > 0 Do
> > begin
> > counter2 := counter2 - 1;
> > read (MYDATA, nextchar);
> > grade:=nextchar;

> > case grade OF
> > 'a' : POINT := 4;
> > 'b' : POINT := 3;
> > 'c' : POINT := 2;
> > 'd' : POINT := 1;

> > else
> > POINT := 0;
> > end;

> > TOTPOINTS:= TOTPOINTS+POINT;
> > grade:=' ';
> > read(mydata,nextchar);
> > hr:=nextchar;

> > case hr of
> > '1':hours:=1;
> > '2':hours:=2;
> > '3':hours:=3;
> > '4':hours:=4;
> > '5':hours:=5;

> > else
> > hours:=0;
> > end;

> > pointsearned:=point*hours;
> > totalpointsearned:=totalpointsearned+pointsearned;
> > totalhours:=totalhours+hours;
> > hr:=' ';
> > pointsearned:=0;
> > end;

> It would be nice to know (without having to examine more closely)
> that your loop ends here. That is why you should indent your code.

> [snipped the output section that seemed to be mostly ok]

> Ok. So at this point we are supposed to have handled a single
> student. Time to re-cap. Is the input file ready for another
> round? No. Remember that you were reading the grades/hours
> one character at a time. Thus the text file pointer is (most likely)
> at the end of the line containing the data related to this student.

> This means that the student id of the next student will begin
> with a carriage return and a line-feed (or was it the reverse order?),
> his/her first name will be the first name of the previous student
> appended by the two last characters of his/her id etc.
> > end;

> [snipped the main program that only uses a single variable 'mydata'
> My style is that variables used by the main program are (more or less)
> the only variables declared in the main VAR-section. There are various
> good reasons for diverting from this rule, but none apply here.]

> Hopefully this will get you started (the list of potential problems
> most likely isn't complete). The best single advice I can give to you
> is to learn to use the de{*filter*}: simply by tracing the code one line
> at a time and watching the key variables suddenly get some unexpected
> values, will pinpoint you most (if not all) of the above errors.

> I don't know Quickbasic, but I don't think your difficulties have
> anything to do with Pascal.

> Good luck,

> Jyrki Lahtonen, Turku, Finland

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.*-*-*.com/ ).
Version: 6.0.417 / Virus Database: 233 - Release Date: 11/8/02


Fri, 27 May 2005 23:02:33 GMT  
 Can anyone help me?
[snip some really great advice]

If you're sure to read the last item of the line, you could use READLN
rather than read, which would get ou to the next line of the file at
once without the need to deal with the line-break.

Greetings and good luck

Markus

PS: Identing is really a good thing! something like

FOR i:=0 TO 10 DO
BEGIN
   n:=n*2;
END;

is better readable...



Sat, 28 May 2005 02:11:06 GMT  
 Can anyone help me?
Another tip of mine:

You use newsgroups which will be quite a help for you. But please be a
help of the other readers here as well: do please delene unecessary
parts of previous texts if you reply to something. Most text of your
reply I replied on was useless for what you had to say this time. It
cost much time to scroll through it, only to see at the bottom that
there was nothing new in it, because you wrote all new thins already at
the beginning. If you do delete such parts, others here will be more
friendly and thus more helpfully to you.

Greetings

Markus



Sat, 28 May 2005 02:14:36 GMT  
 Can anyone help me?
On Sun, 8 Dec 2002 14:04:04 -0600, "Rhonda Sellers"

Quote:

>I am having a terrible time with a Pascal program that I am writing that
>needs to call a dat file. I can't get it to call but the first line and I
>have looked this over for 2 days and can't figure it out. If anyone can help
>me, please email me back. Thanks so much

From your example it looks like you are using "Read" instead of
"Readln" for your textfile. Here is a very simple example using both
text files and a file of records which looks more appropriate for your
assignment. Hope it helps.
Clif

{Reading a text file and storing the data in a random access file of
records. Although written in Turbo v6.0, the approach is similar in
your version. This is the simple textfile used:
     (No blank line at top or bottom of textfile named 'student.txt')
Smith
Ralph
B
Jones
Shirley
A
Brown
John
C

Quote:
}

Program FilingExample;
Const
    source = 'student.txt';  dest = 'roll.dat';
Type
    student = record
                 lname:String[15];
                 fname:String[15];
                 grade:Char;
              end;
    mytype = file of student;
Var
   f1:Text;
   f2:mytype;
   tmp:student;
   ct:Integer;

Procedure ShowData(VAR ff:mytype; recNum:integer);
Var buf:student;
Begin
     Seek(ff, recNum);
     Read(ff, buf);    {reads whole record}
     Writeln(buf.grade, '   ', buf.fname, ' ', buf.lname);
End;

Begin
     Assign(f1, source);       Reset(f1);
     Assign(f2, dest);         Rewrite(f2);

     While not eof(f1) do
     Begin
          Readln(f1, tmp.lname);
          Readln(f1, tmp.fname);
          Readln(f1, tmp.grade);
          Write(f2, tmp);  {writes whole student record}
     End;
     Close(f1);

     (***** Retrieve and display records *****)

     Writeln; Writeln; Writeln ('Stored order':20);
     For ct := 0 to 2 Do  {record numbers start with 0}
     Begin
          ShowData(f2, ct);
     End;

     Writeln; Writeln; Writeln('Random access':20);
     ShowData(f2, 1);
     ShowData(f2, 2);
     ShowData(f2, 0);
     Close(f2);
Readln;
End.



Sat, 28 May 2005 07:17:30 GMT  
 Can anyone help me?

Quote:
> ... you have been a tremendous help. I'm surprised I
> didn't stick any Qbasic commands in there as well. I'm terrible for doing
> that.

I noticed that you never said anything about QBasic as was suggested ? So
you're reacting to the European academics culture ?  It is odd...a
combination of authority and discipline and a threat of outcast if not
following convention. Americans in computer programming do follow convention
but it is more like opinion and debate rather than discipline and
outcast...The bottom line is that this is a Euro newsgroup.

And actually go through the QBasic help files and all features are there. Go
to a QBasic web forum and the code style of the early {*filter*} programmers is as
advanced as any...or otherwise personal development is allowed for instead
of rejection of the individual.

Look at powerbasic for fully advanced Basic or VB for the GUI Basic.



Sun, 29 May 2005 13:10:43 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. It's not bad canned meat...

2. i need help on pascal anyone can help?

3. Help variable reads too far THANX to anyone who tries to help

4. pascal help, can anyone help me to learn pascal

5. can anyone help

6. Can anyone help ?

7. Help! Anyone who knows *.ico format

8. Can anyone help with odbcint.dll error?

9. can anyone help please!!!!!!!!!!!

10. Can anyone help me ?

11. Delphi Database Problem, can anyone help?

12. Can anyone help connect Dephi3 to TopSpeed (*.tps)?

 

 
Powered by phpBB® Forum Software