Printing ?

Hi Friends,

   I have table called tbPrintDesign and tbLine. The structure of the table is as follows

tbLine
_______

  * LineNumber
  * Data To Print  // what data should be printed in that Line Number.

tbPrintDesign
_____________

  * LineNumber
  * LinesPerInch ( LPI )
  * CharacterPerInch ( CPI )
  * LayoutOfData

 I have to get the data from tbLine table, it's respective layout( How to print ) from tbPrintDesign table and show a preview to the end user. If the user says print it should print the document. Please Note : I cannot use Microsoft Word.

 

ArvindtnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mark2150Commented:
Ok, from what I gather you're trying to make a dynamic data printer. You've got a definition table and live data tables.

The printer in VB can be treated as a plotter. If you set the .Scale property you can define the print region in units of your choosing. LPI and CPI don't have direct meaning. You can position the print cursor using .PrinterX/Y. When you want to move down to a new line simply add the spacing from the LPI to the .PrinterY like this:

LPISpace = 1 / LPI
OldY = Printer.CurrentY
Printer.Print "This is some text"
Printer.CurrentY = OldY + LPISpace

CPI really has little meaning when you're using proportionally spaced fonts. You either have to use Courier or some other mono-spaced font or you can determine the space that a specific text object needs by using the .TextWidth or .TextHeight properties.

Now I don't know if you're having data extraction issues as well, but this should get you headed in the right direction as far as printing goes.

M

0
AndySulzCommented:
Use Crystal Reports.
0
ArvindtnAuthor Commented:
i want to do it without crystal reports
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mark2150Commented:
Ok, so follow my example and generate your own report. Set up the printer's .scale and you can position yourself with .CurrentX/Y and print text with Printer.Print RS!Field.

If you need to, say, center a line of text then you can use the .TextWidth property to find out how wide your text is:

Txt = trim( "" & RS!SomeField )
Printer.CurrentX = ColumnN - (Printer.TextWidth(Txt) / 2)
Printer.Print Txt

For Right justified, simply leave off the "/ 2"

Use .Line to draw lines and boxes. All will be denominated in units you've set when you set the .Scale property.

If you need additional pages you can generate them with .Page and you can watch the .CurrentY to tell when you're getting near the bottom of the page.

Finally end the report with .EndDoc

M

0
ArvindtnAuthor Commented:
How will i show the preview then Mark, Will it work in a LinePrinter. Because iam trying it in a Laser printer but the client will use Line Printer Only.
Also is there any method to find whether the printer is ON / OFF, Paper is present in the Printer, etc. The Printer could either be on a Network or directly connected to my machine.

 
0
mark2150Commented:
If you pass the print routine a PictureBox as a parameter, it'll render to the picture box just like it'll render to the printer.

PUBLIC SUB Render( Obj AS Object )
....
END SUB

When you call it with:

DIM MyObj AS Object

Set MyObject = PictureBox1
Call Render( MyObject )

Now it gives you preview. You want hardcopy? Change to:

Set MyObject = Printer
Call Render( MyObject )

You don't have to worry about the details of the printer. No matter what printer or it's paper status or how it's connected your print routine remains unchanged. Remember your app is printing to a *LOGICAL* device - NOT a PHYSICAL one. The *LOGICAL* printer is the SAME no matter what the internal details of the physical printer are. It is the OS's job to convert the data you sent to the logical printer to whatever form is needed by your specific printer.

Your app doesn't need to know or care anything significant about the printer.

You pop the Printer function of the CommonDialog control to allow the user to select what printer they want the job to go to. It matters not if the printer is on a LAN, printing to a file, dot matrix, laser, or what. Once the user has given the go ahead by making a printer selection you set the .SCALE property to convert the page's dimensions to units you like to work in and start hammering out the print commands. When you're done the .EndDoc method signals the OS to convert the logical page your app has created into whatever form is required for the target printer. Your app can be happily continuing on while the print job queues and develops a life of it's own.

M

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArvindtnAuthor Commented:
Thanks for your hints Mark, You gave me a path to approach the problem. Iam giving you the points only for that.

I had one problem which i had sorted out. The problem was in assigning Height and Width to a font. I did that using CreateFont().


I had solved the problem and it is working perfectly. I thank everybody for trying to help me out.

Bye
Arvind

0
mark2150Commented:
Always glad to help.

M
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.