Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing memo fields in VB6 using printer object

Status
Not open for further replies.

moben

IS-IT--Management
Feb 5, 2002
116
GB
Hi,

I'm trying to print memo fields within a VB6 application report.

How do I get it to print multiline, currently it is just printing one line to the right edge of a A4 sheet.

For this report, I cannot use Crystal Reports, as the processign and calculations involved in prepapring the data prior to printing, is far to complex to simply feed into CR.

Any help greatly appreciated.

Moben.
 
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 + &quot; &quot;

ElseIf Asc(ThisChar) > 13 Then

'a &quot;normal&quot; 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) = &quot; &quot; 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 = &quot;&quot;

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) = &quot; &quot; 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 = &quot;&quot;
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 &quot;picked up&quot;
'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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top