Here is some code I developed to deal with printing lines that extended beyond the printable area of the page. You should make MaxWidth a little bit less than the actual printing width, and you will probably nee to adjust LineHeight. Let me know if you have any questions.
Private Sub PrintMultiLineItems(ByVal InText As String, _
ByVal BaseY As Integer, _
ByVal BaseX As Integer, _
ByVal MaxWidth As Integer)
Dim CurrLine As String
Dim TempLine As String
Dim NumChars As Integer
Dim ThisChar As String
Dim NextChar As String
Dim NumExtraLines as Integer
Dim LineHeight as Integer
NumExtraLines = 0
LineHeight = 250
NumChars = 0
'loop through all characters in string
For x = 1 To Len(InText)
'extract current character in string
ThisChar = Mid(InText, x, 1)
'if the current character is not the last character in the string,
'extract the next character
If x < Len(InText) Then
NextChar = Mid(InText, x + 1, 1)
End If
'check if the current character is a carriage return/line feed
If (ThisChar = Chr(10) And NextChar = Chr(13)) Or (ThisChar = Chr(13) And NextChar = Chr(10)) Then
'insert a space in place of cr/lf
CurrLine = CurrLine + " "
ElseIf Asc(ThisChar) > 13 Then
'a "normal" character
'use character as is
CurrLine = CurrLine + ThisChar
End If
'check the printing width of CurrLine is greater than the maximum
'printing width for this string (MaxWidth)
If Picture2(CurrPage).TextWidth(CurrLine) > MaxWidth Then
'check if last character in CurrLine is a space
If Mid(CurrLine, Len(CurrLine), 1) = " " Then
'last char is a space, so print CurrLine and clear it afterward
Picture2(CurrPage).CurrentY = BaseY
Picture2(CurrPage).CurrentX = BaseX + (NumExtraLines * LineHeight)
Picture2(CurrPage).Print CurrLine
CurrLine = ""
Else 'last char is not a space
Do
'extract all but last character of CurrLine
TempLine = Mid(CurrLine, 1, Len(CurrLine) - 1)
'check if last character in CurrLine is a space
If Mid(CurrLine, Len(CurrLine), 1) = " " Then
'last char is a space, so print CurrLine, clear
'it afterward and exit loop
Picture2(CurrPage).CurrentY = BaseY
Picture2(CurrPage).CurrentX = BaseX + (NumExtraLines * LineHeight)
Picture2(CurrPage).Print CurrLine
CurrLine = ""
Exit Do
End If
'assign TempLine to CurrLine (CurrLine is now 1
'char shorter)
CurrLine = TempLine
'decrement x by 1 (so chars cut off can be "picked up"
'again).
x = x - 1
Loop While True
End If
'increment NumExtraLines by 1
NumExtraLines = NumExtraLines + 1
End If
Next x
'print CurrLine
Picture2(CurrPage).CurrentY = BaseY
Picture2(CurrPage).CurrentX = BaseX + (NumExtraLines * LineHeight)
Picture2(CurrPage).Print CurrLine
End Sub
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson