PDA

Click to See Complete Forum and Search --> : Print long texts on the printer


Matt-D
Nov 10th, 1999, 09:48 PM
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)

Ishamel
Nov 10th, 1999, 10:54 PM
I've not tested this, but it might put you on the right track.


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).]