Solved

Printing a text file

Posted on 1998-07-05
8
356 Views
Last Modified: 2012-05-04
Hi I have to do a project in pascal 7 my project is finished
and it saves a report to a text file, now I would like to write a procedure that will test if the printer is on, on-line, has paper in etc and if all these are true, it must print the text file. I need help urgently!! Please.
0
Comment
Question by:Gurkin
[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
8 Comments
 
LVL 1

Accepted Solution

by:
FuzzyLogic earned 50 total points
ID: 1217150
You can use the "printer" unit of TP.
Just add the following line:
  uses Printer;

And you can send whatever you want to the printer by using the file handler "lst":
  Writeln(lst,'Hello world!!!');

Fuzzy
0
 

Author Comment

by:Gurkin
ID: 1217151
FuzzyLogic, thank you, I need to be able to print on WINDOWS95 and MSDOS based printers..... cna you help there??
0
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1217152
I don't know how Win95 handle the printer (I haven't install that bloware on my PC), but I think it will work too under Win95. You just have to check.
And another thing: To check if the printer is OK, you have to call int 17h, service AH=02. You'll get the printer status in the AH:
  Bit0 - TimeOut              Bit5 - Out of paper
  Bit3 - I/O Error            Bit6 - Acknowledge
  Bit4 - Selected             Bit7 - Not Busy

You can call the interrupt using asm statement or use a dos-unit procedure (I don't recall right now what its name, because I don't use it).
Fuzzy
0
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 4

Expert Comment

by:saar2
ID: 1217153
Another solution for you is:

Var
 F:Text;

Begin
 Assign (F,'LPT1');
 Rewrite (F);
 Write (F,'Hello World');
 Write (F,#12) {means end of page}
 Close(F);
End.
0
 

Expert Comment

by:frits
ID: 1217154
Try this unit.
I wasn't able to test it, but it should work.

---------- knip knip -------------------------

UNIT Lister;

INTERFACE

CONST
   prSkipLine  = 1;
   prFormFeed  = 2;
   prBlindMode = 4;

TYPE
   WorkString = string[126];

PROCEDURE PrintLn(PrintStr: WorkString);
FUNCTION CheckOnline : Boolean;

IMPLEMENTATION
USES Crt,Printer;
CONST
  PageWidth   = 80;
  PrintLength = 55;
  PathLength  = 65;

VAR
  CurRow : integer;
  FormFeed:CHAR;
  VerticalTabLength:INTEGER;
  BlindMode:BOOLEAN;

Function CheckOnline : Boolean; Assembler;
ASM
   MOV      AH, 02H     {Int 17,  Service 2 for printer status}
   MOV      AL, 00H     {just playing it safe, probably not needed}
   MOV      DX, 00H     {printer 0}
   INT      17H
   MOV      AL, 00H     {set checkonline false}
   TEST     AH, 10H     {if bit 4 is set z flag=0, if not z flag=1}
   JZ       @No         {leave function false if z flag is set}
   INC      AL
   @No:
END;

Procedure UnderScOn;
   begin
      write(lst,#27#45#1);
   end;

Procedure UnderScOff;
   begin
      write(lst,#27#45#0);
   end;

PROCEDURE VerticalTab;
  VAR i: integer;
  BEGIN
    for i := 1 to VerticalTabLength do Writeln(LST)
  END;

PROCEDURE PrintLn(PrintStr: WorkString);
  BEGIN
    CurRow := Succ(CurRow);
    if Length(PrintStr) > PageWidth then Inc(CurRow);
    if CurRow > PrintLength then
    BEGIN
      Write(LST,FormFeed);
      VerticalTab;
      CurRow := 1;
    END;
    IF PrintStr[1] IN ['!','@'] THEN BEGIN
      UnderScOn;
      WriteLn(LST,COPY(PrintStr,2,LENGTH(PrintStr)-1));
       UnderScOff
    END
    ELSE Writeln(LST,PrintStr)
  END;

END.

-------------------- knip knip -----------------------------

PROGRAM TestLister;

USES Crt,Lister;

BEGIN
   IF CheckOnLine THEN
      PrintLn('Hello world, I`m a printed line.....')
   ELSE
      WriteLn('Printer is off-line....');
   IF ReadKey=#27 THEN HALT
END.

0
 

Author Comment

by:Gurkin
ID: 1217155
Thank you all for the help on printing, It was a real help....
0
 

Expert Comment

by:degraaf
ID: 1217156
You could also use the directives {$I-} and {$I+} to check the outcome of any print instruction. IOResult is set by using this (after reading its value it is reset). A complete list of IO values can be found in the Pascal help file.

For example:

 Assign (F,'LPT1');
{$I-}
 Rewrite (F);
{$I+}
io:=IOResult;
if io<>0 then
{your error handling, depending on error code}

0
 
LVL 7

Expert Comment

by:Motaz
ID: 1217157
(***** This is a very simle code to use a printer to print  *****)
(***** a text file         ***)

uses Printer;

(*********** This function for test if printer ready ************)

Function TestPrinter:boolean;
begin
 {$i-}
  Write(Lst,#7);
 {$i+}
 if IOResult=0 then
   TestPrinter:=True
else
   TestPrinter:=False;
end;

(******** This procedure print a text file send to it ********)

procedure PrintFile(FileName:String);
var
      F:Text;
      St:String[100];
begin
   Assign(F,FileName);
  Reset(F);     (*** Open text file ***)
 
 while Not Eof(F) do  
  begin
    Readln(F,St);     (*** Read line from file ***)
    Writeln(Lst,St);   (*** Write this line into printer ***)
  end;
  Close(F);
  Write(Lst,#12);     (*** Eject the paper ***)
end;

begin
  if TestPrinter then
     PrintFile('Test.txt');
end.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

627 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