Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.34 KB | None | 0 0
  1. unit Results;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.   System.Classes, Vcl.Graphics,
  8.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     Memo1: TMemo;
  13.     Label1: TLabel; // Labels for display
  14.     Label2: TLabel;
  15.     procedure FormActivate(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.     Userfile: textfile;
  21.     TextString, Username: string;
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. procedure TForm1.FormActivate(Sender: TObject);
  32. var
  33.   MemoLineAdd: string;
  34.   done, found: boolean;
  35. begin
  36.   Memo1.Lines.Clear;
  37.   Memo1.Lines.Append(' '); // clearing and resetting file
  38.   Memo1.Lines.Append(' ');
  39.   Memo1.Lines.Append(' ');
  40.   Memo1.Lines.Append(' ');
  41.   AssignFile(Userfile, 'TempUser.txt'); // Open the user using file
  42.   Reset(Userfile);
  43.   readln(Userfile, Username);
  44.   Closefile(Userfile);
  45.   MemoLineAdd := 'Results For ' + Username;
  46.   Memo1.Lines.Append(MemoLineAdd);
  47.  
  48.   AssignFile(Userfile, 'UserData.txt'); // Open the user using file
  49.   Reset(Userfile);
  50.   readln(Userfile, TextString);
  51.   done := false;
  52.   found := false;
  53.   while (done = false) do
  54.   begin
  55.     if (TextString = Username) then
  56.     begin
  57.       found := true;
  58.       readln(Userfile, TextString);
  59.       while (strtoint(TextString) < 100) do
  60.       // JUSTIFICATION:  Usernames and scores need to be differentiated between, since they are both stored in the same file. So since since student numbers are 6 digit figures, and scores 1-2 digits, scores keep being read till a number over 100 is met i.e. the next student number stored.
  61.       begin
  62.         Memo1.Lines.Append(TextString);
  63.         readln(Userfile, TextString);
  64.         if EOF(Userfile) then
  65.         begin
  66.           TextString := '100'; // setting limit
  67.         end;
  68.       end;
  69.       done := true;
  70.     end
  71.     else
  72.     begin
  73.       readln(Userfile, TextString);
  74.       if EOF(Userfile) then // if scores for the current username aren't found
  75.       begin
  76.         if (found = false) then
  77.         begin
  78.           MemoLineAdd := 'No Results Found';
  79.           // display 'no results found' under username
  80.           Memo1.Lines.Append(MemoLineAdd);
  81.         end;
  82.         done := true;
  83.       end;
  84.     end;
  85.   end;
  86.   Closefile(Userfile);
  87. end;
  88.  
  89. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement