|
|
|
|
|
Dicas
|
|
Visual Basic (Impressões/Impressoras)
|
|
|
Título da Dica: Imprimindo texto justificado com objeto printer
|
|
|
|
Postada em 10/6/2004 por Eric Maia
'A função
Function WordWrap(ByVal Text As String, ByVal LineLength As Integer) As String Dim look As String Dim x As Long Dim Y As Long Dim eLine() As String Dim tmp As String
eLine = Split(Text, vbCrLf) If LineLength < 10 Then LineLength = 10 For Y = 0 To UBound(eLine) Do While LineLength < Len(eLine(Y)) DoEvents For x = LineLength To 1 Step -1 look = Mid(eLine(Y), x, 1) Select Case look Case " " tmp = tmp & IIf(tmp > "", vbCrLf, "") & Trim(Left(eLine(Y), x)) eLine(Y) = Right(eLine(Y), Len(eLine(Y)) - x) Exit For Case Else If x < (LineLength / 2) Then tmp = tmp & IIf(tmp > "", vbCrLf, "") & Trim(Left(eLine(Y), LineLength - 1)) & "-" eLine(Y) = Right(eLine(Y), Len(eLine(Y)) - (LineLength - 1)) Exit For End If End Select Next x Loop tmp = tmp & IIf(tmp > "", vbCrLf, "") & eLine(Y) Next Y WordWrap = tmp End Function
'Como usar Texto = WordWrap(TEXTO, Nº CARACTERES DESEJADOS) Printer.Print Texto Printer.EndDoc
xD
|
|
|
|
|