Recent

Author Topic: need help with calender  (Read 49806 times)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #105 on: September 23, 2017, 04:27:11 pm »
what do you mean by that? isn't that the same stuff?
No.

If you do rank[i]:=rank[i] then you just do nothing. You assign the same record to the same record.

But you have just read a record named info from the file.
You want that record info to be copied to the rank-array.
How do you do that.

(I think you need a cup of coffee because I don't think you can think straight at the moment :D)

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #106 on: September 23, 2017, 04:30:18 pm »
can you just tell me please i will never figure it out. i really want to know

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #107 on: September 23, 2017, 04:32:24 pm »
You had:
Code: Pascal  [Select][+][-]
  1. read(highscorefile, info);
  2. if  i < 10 then read(highscorefile, rank[i]);
It needs to be
Code: Pascal  [Select][+][-]
  1. read(highscorefile, info);
  2. if  i <= 10 then rank[i] := info;
That's it.

(And don't forget to open the file above while and close the file below the end of while.)

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #108 on: September 23, 2017, 04:34:08 pm »
isn't that same as rank:=rank ?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #109 on: September 23, 2017, 04:35:10 pm »
isn't that same as rank:=rank ?
You mean is rank[i] := info; the same as rank[i] := rank[i] ??

No.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #110 on: September 23, 2017, 04:36:43 pm »
how arent they both highscorefile?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #111 on: September 23, 2017, 04:41:07 pm »
how arent they both highscorefile?
One (info) is a record you have just READ OUT the highscorefile.
The other (rank[ i ]) is an array item which is locally in memory.

Once you have read the records in that rank array, you don't have anything more to do with the file until you want to write that array back again to the file.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #112 on: September 24, 2017, 02:17:43 am »
Hi i can compile now but the score board is still not coming up

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   if fileexists('highscore.dat') then
  4.   begin
  5.  
  6.     begin
  7.     for i:=1 to 10 do
  8.       rank[i] := info;
  9.     write(highscorefile, info);
  10.     end;
  11.      closefile(highscorefile);
  12.   end;
  13.  
  14. end;
  15.  
  16.  
  17. procedure TForm1.FormCreate(Sender: TObject);
  18. begin
  19.   edit1.clear;
  20.   edit2.clear;
  21.   assignfile(highscorefile, 'highhscore.dat');
  22.   if not fileexists('highhscore.dat') then
  23.   begin
  24.     rewrite(highscorefile);
  25.     closefile(highscorefile);
  26.   end
  27.   else
  28.   begin
  29.   reset(highscorefile);
  30.   i:=1;
  31.    while not eof(highscorefile) do
  32.     begin
  33.     read(highscorefile, info);
  34.  
  35.     if  i <= 10 then rank[i] := info;
  36.  
  37.  
  38.     i:=i+1;
  39.     end;
  40.    closefile(highscorefile);
  41.   end;
  42.  
  43.  
  44.   for i:=1 to 10 do
  45.   if rank[i].score <> 0 then
  46.    begin
  47.     sgdata.Cells[1,i]:=rank[i].name;
  48.     sgdata.cells[2,i]:=inttostr(rank[i].score);
  49.    end;
  50.   end;
  51.  
  52.                                                      

is this code right?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #113 on: September 24, 2017, 02:45:13 am »
Don't you get an error message when you close your program??

In the FormClose you don't open the file. So the writing to the highscorefile should fail with an exception.

But you don't need to check if the file exists in the FormClose. You can just issue an rewrite(highscorefile); because you always want the file to be created on close.

Then in FormClose you have this:
Code: Pascal  [Select][+][-]
  1. for i:=1 to 10 do
  2.     rank[i] := info;
  3. write(highscorefile, info);
Again... please look at what that does.
You want the rank[1], rank[2] etc saved to the file.

But you just assign info (which had no valid value at this point) to the current rank position on 1 to 10.
And then you write ONE record info (still invalid info) to the file.

Try to fix it that you write rank[1], rank[2] etc to the file.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #114 on: September 24, 2017, 03:05:17 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.     for i:=1 to 10 do
  4.     info:=rank[i];
  5.     reset(highscorefile);
  6.     rewrite(highscorefile);
  7.     closefile(highscorefile);
  8.   end;                        

should it be like this?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #115 on: September 24, 2017, 03:12:52 am »
should it be like this?
Nope.

You really need to figure this out yourself otherwise you won't be able to do anything.

You open the file for writing.
You loop through the rank-array and write each rank-record to the file.
And you close the file.

In the formclose you don't even need the whole info variable.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: need help with calender
« Reply #116 on: September 24, 2017, 03:35:19 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.  i:=1;
  4.  reset(highscorefile);
  5.  if i <= 10 then
  6.   begin
  7.    write(highscorefile, rank[i]);
  8.    i:=i+1;
  9.   end;
  10.   closefile(highscorefile);
  11.  end;      

this?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #117 on: September 24, 2017, 08:35:47 am »
this?
Does it work?

What do you see after the second run?

How many records do you think that writes to the file?

bytebites

  • Hero Member
  • *****
  • Posts: 640
Re: need help with calender
« Reply #118 on: September 24, 2017, 08:59:23 am »
Besides that, see that you open same file that you wrote earlier.

Quote
highhscore.dat

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: need help with calender
« Reply #119 on: September 24, 2017, 09:09:44 am »
Besides that, see that you open same file that you wrote earlier.
Quote
highhscore.dat
There is only one AssignFile() in the whole code, in FormCreate, so that never changes.

Somehow rhong7 forgot how to write a loop or what a simple assignment does. I don't understand how the knowledge level can drop so fast from the first few posts.

Maybe rhong7 should begin at the beginning again with some simple programming techniques in Pascal.

 

TinyPortal © 2005-2018