Solved

Printing from a VB app

Posted on 1999-01-28
4
160 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

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