?
Solved

How to see the data printed to a file

Posted on 2002-03-21
4
Medium Priority
?
212 Views
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?
0
Comment
Question by:wizard61
[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
4 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 100 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

Becomes:

MyPr.Line(10,20,30,40,RGB(10,20,30),"BF")

Example:

Public Sub Print(DataItem)

Redim Params(2)
Params(0)="PRINT"
Params(1)=MyCurrentx
Params(2)=MyCurrenty

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
    OpenSpoolFile
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

cmd=""
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
Else
  Set Pr = Printer
End If

PS=1

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

Loop

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 = ""
Else
    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
           etc.
        End Select
 
    Case = "FONT"
        Pr.Font.Name = Params(1)
        Pr.Font.Size = Val(Params(1))  * zf
        Pr.Font.Bold = Val(Params(1))
   
     etc....
End Select

End Sub

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

Author Comment

by:wizard61
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?
0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7666101
Moving to the Paq

kb
Experts Exchange Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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