How to see the data printed to a file

Posted on 2002-03-21
Last Modified: 2010-05-02
I created a "printer" that directs its output to a file. I look at the file in wordpad but I want to see a WYSIWYG view.

I need to write a series of reports and I do not want to kill a tree. I am looking into a Print Preview tool that would help, but I'd still like to be able to output print files and use them later.

I would also like to actually print some of these files, but how do I get the printer to understand that this is a printfile.

I have vague memories of a .prn file type.... Is there a viewer application (PrintViewer) of some kind? Or an option in Word or WordPad or....

I am hoping the answer is "Duh- just use BlahBlah" but if there is more to it I'll bump up the miserly 25 points.

Also, is there an easy way to default the outfile to clear and reuse the same print file each time?
Question by:wizard61
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
LVL 17

Accepted Solution

inthedark earned 25 total points
ID: 6886823
There is a simple answer emulate the printer object as a class module.  So here is some code which you can extened to meet your needs.

In the MyprClass you create all of the methods normally used in the printer. So in your report:

Dim MyPr as MyPRClass
Set MyPr = New MyPrClass

Instead of directly updating the printer you save the data to a file with a command for each operation.

You place a variable length command in the file but the trick is to prefix each command with a fixed length section to make read back simple.

You have to make some changes to you code but only small changes:

Printer.Line (10,20)- (30,40), RGB(10,20,30), BF




Public Sub Print(DataItem)

Redim Params(2)

SaveCommand Params,VarDataItem

End Sub

Public Sub Line(X1,Y1,X2,Y2,Color,BFParam)

Redim Params(6)
Params(0) = "LINE"
Params(1) = X1
Params(2) = Y1
Params(3) = X2
Params(4) = Y2
Params(5) = Color
Params(6) = BFParam

SaveCommand Params, ""

End Sub

Sub SaveCommand(Params, DataItem)

If MySpoolLfn<1 then
End if

HasFontChanged ' Call a sub that detects if font details have changed and saves a command first

dim CC as long
Dim Cmd as String

For CC=0 To UBound(Params)
    CMD = CMD + Cstr(Params(CC) + "|"
Next CC

' Rec is 10+Sep+4+Sep+Command+Data

Rec = format(len(CMD) + len(DataItem) + 16, "0000000000") + "|" + Format(Len(CMD),"0000") + "|" + CMD + DataItem

Put MySpoolLfn,Lof(MySpoolLfn)+1,Rec

End Sub

In the example above the numeric arguemnts are converted to strings.  But in graphics methods the picture to be printed will be a string of bytes.

To read back the file just get the first 16 bytes then you know how much to read:

Sub SpoolFile(PreView as Boolean, ZoomPercent)

zf = ZoomPercent / 100

If PreView Then
  Set PR  = frmDummy.picDummy
  Set Pr = Printer
End If


    If ps>Lof(MySpoolLFN) Then Exit Sub
    Get MySpoolLfn, PS, Rec
    BL = Val(Left(Rec,10)) ' Whole Length
    Rec = Space$(BL)
    Get MySpoolLfn, PS, Rec
    Process(Rec, Pr)


End Sub

Sub Process(Rec, Pr)

' First Extrct Params

ReDim Params(0) as string

TL = Val(Mid(Rec,1,10)) ' Whole length of record
CL = Val(Mid(Rec,12,4)) ' Length of Command

Params = Split(Mid(Rec,17, CL), "|")

DL = TL - CL - 16

If DL = 0 Then
    VarData = ""
    VarData = Mid(Rec, CL + 17)
End If

Select Case Ucase(Params(0))
    Case = "PRINT"
        Pr.CurrentX = Val(Params(1)) * zf
        Pr.CurrentY = Val(Params(2)) * zf
        PR.Print VarData;
    CASE = "LINE"
        X1 = Val(Params(1)) * zf
        Y1 = Val(Params(2)) * zf
        X2 = Val(Params(3)) * zf
        Y2 = Val(Params(4)) * zf
        Color = Val(Params(5))
        BFParam = Params(6)
        Select Case BFParam
           CASE = "BF"
              Pr.Line (X1,Y1) - (X2, Y2), Color, BF
        End Select
    Case = "FONT"
        Pr.Font.Name = Params(1)
        Pr.Font.Size = Val(Params(1))  * zf
        Pr.Font.Bold = Val(Params(1))
End Select

End Sub

I will leave you to do the rest, it is not rocket science.

Author Comment

ID: 6894845
After looking at this for a while, I left wishing I had the time to spend making something nice.

Is there a 3rd party ocx that anyone can suggest for this?
LVL 49

Expert Comment

ID: 7634224
Hi wizard61,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept inthedark's comment(s) as an answer.

wizard61, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7666101
Moving to the Paq

Experts Exchange Moderator

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

726 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