Solved

Printing a text file

Posted on 1998-07-05
8
350 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
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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now