Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TYPE prints the output on screen how to stop that ? 2

Status
Not open for further replies.

A_Radiolog_inFoxPro

IS-IT--Management
Mar 29, 2020
41
CY
Dear All ,

I have this command " TYPE 'some file' TO PRINTER

And it outputs the file contents on screen.

Is there a way to stop that ?

Thanks in advance for the help ,

The Radiologist
 
I don't see an option to only print to printer.

So the best answer would be not to use TYPE.

Chriss
 
Okay , so I want to send RAW data to a printer. How can I do that with out TYPE ?

Thanks

The Radiologist
 
A quite bad workaround ( I would like to avoid it at all costs )
SET CONSOLE OFF
TYPE 'some file' TO PRINTER
SET CONSOLE ON

If you have a more elegant solution let me know.
 
It's not a "bad workaround". SET CONSOLE OFF is the usual way of dealing with this sort of situation. In fact, it's not unusual to SET CONSOLE OFF at the start of a program and to leave it OFF throughout the session. Off-hand, I can't think of any circumstances when I would want it to be ON within a program (but that doesn't apply when working in the development environment).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Dear Mike ,

Thank you for your input.

In my case the console is the program form. My guy is "drawing" on the display :D old School Fox Pro stuff.

Thanks

The Radiologist
 
In my case the console is the program form. My guy is "drawing" on the display

I take that to mean that the output of the TYPE is appearing in a form rather than on the background. That's normal. Whenever a form is open and active, it receives any output that would otherwise go to the background of the main VFP window (aka _SCREEN). That applies to commands such as ?, LIST, @/SAY, CLEAR and the output from SET TALK - and even a BROWSE window.

To change that behaviour, set the form's AllowOutput property to .F. You can also do ACTIVATE SCREEN. But you still need to SET CONSOLE OFF to prevent it going to _SCREEN.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you don't want to switch console off, the logical alternative is using a form that will do the TYPE and accept the output to itself, while it's off screen.

Create a standard VFP form, with this in Form.Init:
Code:
Lparameters tcFile

This.Tag = tcFile

And this in Form.Activate:
Code:
This.Left = -2*Sysmetric(1)
This.Top = -2*Sysmetric(2)

Thisform.Caption = JustStem(Thisform.cFile)
Type (Thisform.Tag) To Printer
Thisform.Release()

Save it as typeform.scx

Instead of setting Left and Top in activate you could set the properties to =expression to have that done already before activate happens, but I don't see the form even just flash for a millisecond.

I saw another benefit of doing it with the help of a form, using PDF Creator: The form caption becomes the pdf file name, so I used that and set the caption to the stem of the filename to print.

Usage then is
Code:
DO Form typeform with "filename" && or a variable with the filename, of course

Chriss
 
Chris suggests creating a special form to hold the output, and placing it off the screen. That seems to be a good solution. Another possibility would be to set the form's Visible property to .F., which would give the same result.

Also, you wouldn't need to create the form each time you need it and then release it afterwards. By keeping it open (and invisible) throughout the session, you simplify the whole process, and also save a few milliseconds each time you need it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I intentionally kept it visible, otherwise you lose the benefit of having the form caption as file name when using a PDFCreator as the printer. If the form is made invisible PDFCreator will pick another form title. For example I got output as "Desktop - Properties.pdf" instead.

The idea to keep the form alive all time for all type outputs means you have to find a way to trigger printing with other filenames, not impossible, but I don't see a big benefit in that and the easy of using a parameter makes it just a llittle different to the usual TYPE command. The time it takes to TYPE the output is already much faster by the form being off screen in comparson to keeping it within the display. I guess the form still get's paint events, but does not paint by being off and so that already makes it fast, no need to make it invisible for that acceleration.

All in all, a form that has nothing on it and only this small code portion in init and activate does the job for me, if I ever would need it.

Chriss
 
Unimportant details, but anyway:

If you use the NOSHOW clause in the DO FORM you suppress the Activate event and thus don't run the TYPE code.

If you call Thisform.Hide() or set Thiform.visible = .f. in the init the DO FORM still shows the form as making the form visible comes after the init event, so I don't see a way that works except putting the from far off screen.

The straight forward way is to SET CONSOLE OFF, anyway. I wouldn't have posted this alternative, if there wasn't that benefit with PDFCreator. I haven't tried with other virtual printers thet generate files, like One Note or others. The benefit becomes unimportant, if you print to an actual printer, of course.

Chriss
 
Also, if you kept it invisible, you would need a way of activating it so that it can receive the output from TYPE, etc. And as soon as you activate it, it becomes visible, which would defeat the object. So, from that point of view, keeping it off-screen would be a better option.

I only raised all this because the OP talked about the output going to the "program form".

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
And I gave this alternative because of the benefit I saw and because it means you can keep CONSOLE ON, as that seems to be desired. Any events that cause output to "the console" would then continue to work and just the output of TYPE is captured in the extra form.

If instead you just use SET CONSOLE OFF, it's merely a short interval of TYPE outputting the file to the printer spooler anyway, and afterwards you can go back to SETE CONSOLE ON.

Chriss
 
Speaking of other alternatives: the Windows Shell TYPE command, the Generic/Text printer driver and the ??? command.

Chriss
 
Dear Mr.Chris

At the moment I am changing the printer from default to the Text only generic printer driver so that I can push the ZPL code directly to the printer to avoid having to deal with math creating QR codes but my printer can do that out of the box.

Thank everyone for all the ideas and help , making an other form and putting it off screen seems an interesting idea , I will try to capitalise on that BUT the programmer did some magic that detects if the program is out of the screen resolution. So I might have an issue with this solution plus some PCs have 2 screens so off screens won't be off screen.

and maybe try the cmd method.

I will try to test all ideas and see how everything pans out.

I would like to once again thank everyone for their valuable input and the time , with out you, I wouldn't be able to maintain this old software :D

Thank you in advance

The Radiologist

 
A_Radiolog_inFoxPro said:
the programmer did some magic that detects if the program is out of the screen resolution
That's done at start and concerns the main top level form or _screen, doesn't it? After that is done, new forms can still have any off screen coordinates...

Even if a base form has something programmed into it that shifts every form into the visible desktop, you can simply override that.

A_Radiolog_inFoxPro said:
so off screens won't be off screen.
...Notice I used negative coordinates. And twice the display width and height. You can go more extreme, it won't be on the second display.

Chriss
 
Hello,

what about set alternate to (a file) and copy /b that file to printer ?

Regards
tom

I remember a tool called dosprint and a dirprtclass, but thats too long ago for me.
I
 
I used the command under VP 6.0 for printing: "Copy File FileName.TXT To LPT1.DOS" or "Copy File FileName.TXT To LPT2.DOS". The text files contained PCL commands controlling settings of printers. Using the command: "net use" it was possible to map the LPT1 or LPT2 port to the USB printer. I used this solution several years ago under Windows 7 (64 bit). It wasn't stable. Before each printing, mapping had to be done.
 
Yes, there have been more suggestions, for example about using the Shell TYPE command, too, with output to printer by >LPT1, for example.

If you know VFPs TYPE worked for you, it's the simplest to stay with it and then just use a trick to hide its output, the simplest, of course, being SET CONSOLE OFF. In some ways the DOS commands are not wrong and some of that is are pat of Windows cmd.exe, still in Win11, too. A setup of a printer using the Generic/Text printer driver lets you pick output to a (virtual) COM port driven by USB, LPT, and I'm sure I forgot one or two more options, there's no reason to install a whole DOS to get back to the full DOS command capabilities for that one feature, though.

The Windows Shell cmd.exe still knows the TYPE command and that will require piping output to a printer which you can do after NET USE printer, for example, if >LPT1 is too simple, as todays computers only have US_B ports. There's also the PRINT command, that would perhaps fit better than piping TYPE output somewhere.

COPY indeed can also copy a file not only into a new destination file, but to a network UNC path name of a printer or an output device name you map by NET USE, too. May require some permission related specifics, I'm not the expert for all this. But you surely don't need more than VFP and Windows to get a file with printer commands directly to it.

Chriss
 
Exactly Chriss :)

I found an old script: "net use LPT1 \\ComputerName\PrinterName /persistent.yes" :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top