Results 1 to 2 of 2

Thread: Print long texts on the printer

  1. #1

    Thread Starter
    Hyperactive Member Matt-D's Avatar
    Join Date
    Nov 1999
    Location
    Mettmann, Germany
    Posts
    305

    Post

    There is a text-box with a long text and I want to print it out on the printer. But the printer only prints one line !!!!!!! with this method:

    PRINTER.Print Text1.text
    PRINTER.EndDoc

    Can anybody help me ?

    Important: I make this programm in VB 3.0
    (I have also VB 6.0)

  2. #2
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112

    Post

    I've not tested this, but it might put you on the right track.

    Code:
    Dim pos As Integer
    Dim length As Integer
    Dim iRow As Integer
    
    
    'Call a function to get the number of lines required.
    iNumberOfLines = GetNumberOfLines(Text1.Text, [Place Page/Column Width here])
    
    
    'Now that we have the number of lines required, print the string.
    Call PrintString(CStr(Text1.Text), [Place Page/Column width her], iNumberOfLines)
    
    
    Public Function GetNumberOfLines(sText As String, iWidth As Integer) As Integer
    
        Dim iCounter As Integer
        
        iCounter = 0
        
        Do
            If IsNull(sText) Then Exit Do
            
            pos = InStr(sText, vbCr)
            length = Len(sText)
            
            If (pos < iWidth) And (pos <> 0) Then
                sText = Mid(sText, pos + 1)
                iCounter = iCounter + 1
            ElseIf (length > iWidth) Then
                pos = iWidth
                
                Do While ((Mid(sText, pos, 1) <> " ") And (Mid(sText, iWidth + 1, 1) <> " "))
                    pos = pos - 1
                    
                    If (pos = 0) Then
                        pos = iWidth
                        Exit Do
                    End If
                    
                Loop
                
                sText = Mid(sText, pos + 1)
                iCounter = iCounter + 1
            Else
                iCounter = iCounter + 1
                sText = ""
            End If
            
        Loop Until sText = ""
        
        GetNumberOfLines = iCounter
    End Function
    
    
    ' This procedure prints a multi-line string correctly
    Sub PrintString(sText As String, iWidth As Integer, iHeight As Integer)
    
        Dim iCounter As Integer
        
        For iCounter = 1 To iHeight
        
            If IsNull(sText) Then Exit Sub
            
            pos = InStr(sText, vbCr)
    
            length = Len(sText)
            
            If (pos < iWidth) And (pos <> 0) Then
            
                Call PrintText(sText, iRow)
                
                sText = Mid(sText, pos + 1)
            ElseIf (length > iWidth) Then
                pos = iWidth
                
                Do While ((Mid(sText, pos, 1) <> " ") And (Mid(sText, iWidth + 1, 1) <> " "))
                    pos = pos - 1
                    
                    If (pos = 0) Then
                        pos = iWidth
                        Exit Do
                    End If
                Loop
                
                Call PrintText(sText, iRow)
                
                sText = Mid(sText, pos + 1)
            Else
                Call PrintText(sText, iRow)
                sText = ""
            End If
            
            iRow = iRow + 1
        Next
    
        Printer.EndDoc
    End Sub
    
    
    Sub PrintText(sText As String, iRow As Integer)
        Printer.CurrentY = iRow
        Printer.Print sText
    End Sub

    [This message has been edited by Ishamel (edited 11-11-1999).]

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