Solved

Printing from a VB app

Posted on 1999-01-28
4
159 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

726 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