Solved

How to see the data printed to a file

Posted on 2002-03-21
4
191 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
4 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 25 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Moving to the Paq

kb
Experts Exchange Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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

11 Experts available now in Live!

Get 1:1 Help Now