Advertisement
klasscho

Untitled

Feb 18th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. procedure ReadFromFile(var Words: String);
  2. var
  3. FileName: String;
  4. IsCorrect, CorrectName: Boolean;
  5. InFile: Text;
  6. begin
  7. repeat
  8. Writeln('Enter a file name for data entry in the format Name.txt');
  9. repeat
  10. Readln(FileName);
  11. if FileExists(FileName) then
  12. CorrectName := True
  13. else
  14. begin
  15. Writeln('The file name was entered incorrectly. Try again. Example: Name.txt');
  16. CorrectName := False;
  17. end;
  18. until CorrectName;
  19. IsCorrect := True;
  20. Assign(InFile, FileName);
  21. Reset(InFile);
  22. if IOResult <> 0 then
  23. begin
  24. Writeln(' File does not exist!');
  25. IsCorrect := False;
  26. end
  27. else
  28. begin
  29. Read(InFile, Words);
  30. if length(Words) = 0 then
  31. begin
  32. Writeln('File is empty!');
  33. IsCorrect := False;
  34. end;
  35. end;
  36. until IsCorrect;
  37. Close(InFile);
  38. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement