Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing a text file

Posted on 1998-07-05
8
Medium Priority
?
358 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 100 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
What we learned in Webroot's webinar on multi-vector protection.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 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