Solved

Printing from a VB app

Posted on 1999-01-28
4
156 Views
Last Modified: 2008-03-10
I am using the following code to print the details from a screen in my VB app :

Set OutputObject = Printer

    OutputObject.Print "Print Example"
    OutputObject.Print vbLf
    OutputObject.Print txtDescription
    OutputObject.Print "How do i do this"
    OutputObject.EndDoc

When I the field txtDescription has many lines of text (as appears on the screen), when it is printed it is cut off at the end of the line, instead of wrapping automatically to the next line.  Is there an easy way of doing this, rather than writing a routine to split the string up into several strings based on the width of the page?
Thanks.
0
Comment
Question by:gbr
  • 2
4 Comments
 

Expert Comment

by:spardog
ID: 1471054
go to www.vb-world.net and search the download able files for word warp and there is a good script there
0
 

Author Comment

by:gbr
ID: 1471055
this doesn't really apply to my problem.
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 30 total points
ID: 1471056
No, there is no simple way to get the printer to wrap the text. If you use a rich text box you can (sort of) do it, but it's fugly and you lose other formatting options. Here is a routine to wrap text for you:

Call PrintLongText(Text2.Text)


Sub PrintLongText(LongText As String)
'
' This procedure prints a text stream to a printer and
' ensures that words are not split between lines and
' that they wrap as needed.
'
    Printer.CurrentX = leftedge
    Do Until LongText = ""
'
' current word is null
'
        word$ = ""
'
'        look for crlf in text
'
        marker1 = InStr(LongText, vbCrLf)
'
' Look for space in line of text
'
        marker = InStr(LongText, " ")
'
' Give preference to CRLF if present
'
        If marker1 < marker Then
            crflag = True
            marker = marker1
        Else
            crflag = False
        End If
'
        If marker > 0 Then
'
' If we've found a space, get left part as current word and strip
' it off the line
'
            word$ = LTrim$(RTrim$(Left$(LongText, marker - 1)))
            LongText = Right$(LongText, Len(LongText) - marker)
            If Left$(LongText, 1) = Chr$(10) Then LongText = Right$(LongText, Len(LongText) - 1)
        Else
'
' Only one word left, take it and close out line of text
'
            word$ = LTrim$(RTrim$(LongText))
            LongText = ""
        End If
'
' Force a newline if we're getting to the end of the current line
'
        If Printer.TextWidth(word$) + Printer.CurrentX > rightedge - Printer.TextWidth(String$(Len(word$), "Z")) Then crflag = True
'
' Print a space and the next word of the message
'
        If crflag = True Then
            Printer.Print word$
            Printer.CurrentX = leftedge
        Else
            Printer.Print word$; " ";
        End If
'
' Repeat until line of text is gone
'
    Loop
    Printer.Print
    Printer.CurrentX = leftedge
End Sub


That's a lot of code for what should have been a simple internal function. Printing in VB seems to be an after-thought rather than a designed in feature. (sigh)

M

0
 

Author Comment

by:gbr
ID: 1471057
Thank for your help.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now