Results 1 to 7 of 7

Thread: <resolved> Printing a multiline textbox

  1. #1

    Thread Starter
    Addicted Member SaharaWizard's Avatar
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    254

    Resolved <resolved> Printing a multiline textbox

    Hello guys
    I am printing a multiline textbox (let's say 3 lines of text) with the following code:
    '------------
    printer.currentX=1000
    Printer.CurrentY =1000
    printer.print txtMyNotes.text
    '-----------
    As you might guess the first line will be printed on the (1000,1000) coordinates but the second line of text will be printer at start of the next line (Something like 0,1100) !
    How can I make sure the other lines of multiline text are alligned same as the first line in one bulk?
    Thanks
    SW
    PS. The data in the multiline textbox is coming frm an Access 2000 database.
    Last edited by SaharaWizard; Apr 13th, 2005 at 11:57 AM.
    Don't let your schooling get in the way of your education.

  2. #2
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Printing a multiline textbox

    can u print one line at a time? then you could set the x value to 1000 before printing each line
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  3. #3

    Thread Starter
    Addicted Member SaharaWizard's Avatar
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    254

    Question How?

    How?
    Don't let your schooling get in the way of your education.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Printing a multiline textbox

    I'm not entirely sure that the CurrentY will increment properly automatically, but this should be it:
    VB Code:
    1. Dim tmpSplit as Variant
    2. Dim iCount as Integer
    3.   tmpSplit = Split(txtMyNotes.text, vbCrLf)
    4.   Printer.CurrentY =1000
    5.   For iCount = 0 to Ubound(tmpSplit)
    6.     printer.currentX=1000
    7.     printer.print tmpSplit(iCount)
    8.   Next iCount


    Moved to appropriate forum - this is not a DB question!

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Printing a multiline textbox

    First, the CRLF in the multi-line textbox is not always present - autowrapping causes it to look like a 3 line textbox, but it can actually be one line.

    This function will put "real" CRLF's into the textbox string.

    Code:
            strText = Wrap_Text(flxPosting.TextMatrix(x, CLng(gstrCurMP)), 3.9167 * 1440)
            Printer.Print strText
    This is the actual function:

    Code:
    Private Function Wrap_Text(ByVal strText As String, lngWidth As Long) As String
    
    Dim x As Long, y As Long, z As Long, s1 As String
    
    s1 = ""
    
    Do While strText <> ""
        For x = 1 To Len(strText)
            Select Case Asc(Mid$(strText, x, 1))
                Case 32
                    y = x
                Case 13
                    Debug.Print "Got 13"
                Case 10
                    Debug.Print "Got 10"
                    z = x
            End Select
            If z <> 0 Then
                Debug.Print Left(strText, z - 2)
                If s1 <> "" Then s1 = s1 & vbCrLf
                s1 = s1 & Left(strText, z - 2)
                strText = Mid(strText, z + 1)
                z = 0
                Exit For
            End If
            If frmTeaMark.TextWidth(Left(strText, x)) > lngWidth Then
                Debug.Print Left(strText, y - 1)
                If s1 <> "" Then s1 = s1 & vbCrLf
                s1 = s1 & Left(strText, y - 1)
                strText = Mid(strText, y + 1)
                Exit For
            End If
            If x = Len(strText) Then
                Debug.Print strText
                If s1 <> "" Then s1 = s1 & vbCrLf
                s1 = s1 & strText
                strText = ""
                Exit For
            End If
        Next x
    Loop
    
    Wrap_Text = s1
    
    End Function
    But in your case - you need to use SPLIT to break up the string returned by the WRAP_TEXT function on the vbCrLF - into an array - and then print each line of the array and set the .CURRENTX to 1000 first.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Printing a multiline textbox

    Good point, I hadn't thought that the scrollbar(s) might be disabled!

    Just one point, your usage example is a little confusing! Am I right in thinking that in this case it could be added to my example like this?
    VB Code:
    1. Dim iCount as Integer
    2. Dim strText as String
    3.   strText = Wrap_Text(txtMyNotes.text, txtMyNotes.Width)
    4.   tmpSplit = Split(strText, vbCrLf)

    oh, and in the (rather useful!) function, frmTeaMark should be replaced with the name of your form.

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Printing a multiline textbox

    Thanks SI - I'm in a rush here - it's a push-push world and I can barely keep up...

    Yes - your code clarifies the usage for this thread starter...

    And in the function itself "frmTeaMark" should be replaced with a form or whatever object has a good fontname, size and style to match what you are dealing with.

    [edit] The function might not be commented well - but I do use DEBUG.PRINT all over!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width