Discussion Locked

Printing in VB 6

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have text that I need to print however it is printing off of the righ hand side of the page. Is there any way in VB perform a wrap.

9 replies

by lo

Hi - I took a quick look in VB and didn't see any function that might format text where you would pass it a block of text and have it format into N character lines. I would assume there is one there somewhere but ... You can write one yourself if you can't find one. If you are getting data from a text box (or other control) there is a property that will wrap, but I think that only controls display, there may be a way to return it with line breaks, but ... If you are writing multiple lines that have more characters than the printer width, just break it into multiple print statements. As a last thought, there may be a way to set the printer (physically) or the Windows queue to do the wrap for you but ... lo

by techrepublic

There are many things that you can do with Visual basic's print object, but I suggest you use another method. I used that method is a slow process to hand code every movement on the printer, although possible.

I feel there are 2 better options..
1) You could use the Visual Basic data report designer for database reporting without pictures
2) Probably the best option is Crystal reports or Active Reports. If you own VB 5 it is available as a separate install off the VB 5 installation diskette.
3) Buy Crystal Dev Edition 8 or Active Reports from xtras.com or somewhere.

Crystal gives a number of options to put data from anywhere to a report, including pictures from a database.

I am talking to you from experience. I once createda full page of bar codes and lines and information and got it working well on one printer. The real issues came in when the printer drivers were a bit different.

good luck

by mykrotek

Have you looked at using the DrawText API call? This function allows you to define a rectangular area to place the text, and will word wrap the text automatically for you (providing you set the appropriate flags). Check online at Microsoft.com forinfo on using the DrawText API with VB.

by burtsa

Personally I use a print utility from Pegasus Software, but assuming you want to do it with your own code you will have to write your own wrap function. I would suggest testing the length of the text in pixels using a function like PrinterObj.TextWidth(Str_Var)

This discussion is closed to new replies.