Hallo, stehe wieder an einer hürde an der ich nicht vorbei komme.
Es dreht sich um das drucken von Datensätzen mit Zeilenumbruch.
In der Zeile If .TextWidth(sLine(I)) <= MaxWidth Then kommt ein Laufzeitfehler 6 ohne Text.
Nach Informationen aus Google zur urteilen heist das ein Überlauf statgefunden hat. Nur weiß ich nicht Warum u. Wieso?
Das ist ein Teil des Codes wo der Fehler auftritt.
Public Sub PrintMultilineText(ByVal sText As String, _
Optional ByVal xPos As Long = 0, _
Optional ByVal yPos As Long = 0, _
Optional ByVal MaxWidth As Long = 0, _
Optional ByVal MaxHeight As Long = 0, _
Optional ByVal sUmbruch As Boolean = False, _
Optional ByVal tAlign As Integer = 0)
Dim sLine() As String
Dim I As Integer
Dim NextLine As String
Dim y2 As Long
With Printer
' Wenn xPos, yPos = 0, aktuelle Position ermitteln
If xPos = 0 Then xPos = .CurrentX
If yPos = 0 Then
yPos = .CurrentY
Else
.CurrentY = yPos
End If
' Maximale Druckbreite für die Textbox
If MaxWidth = 0 Then
MaxWidth = .ScaleWidth - xPos
ElseIf MaxWidth < 0 Then
MaxWidth = .ScaleWidth - xPos - Abs(MaxWidth)
End If
' Maximale Druckhöhe
If MaxHeight = 0 Then
y2 = .ScaleHeight - yPos
ElseIf MaxHeight < 0 Then
y2 = .ScaleHeight - yPos - Abs(MaxHeight)
Else
y2 = yPos + MaxHeight
End If
' zunächst die "harten" Zeilenumbrüche ermitteln
sLine = Split(sText, vbCrLf)
For I = 0 To UBound(sLine)
>>If .TextWidth(sLine(I)) <= MaxWidth Then<<
' Zeile hat keine "Überbreite"
' wenn nicht mehr ins Rechteck (maxHeight)
' passt, Prozedur verlassen
If Not CheckTextHeight(sLine(I), .CurrentY, _
y2, MaxHeight, sUmbruch) Then Exit For
' Ausrichtung
Select Case tAlign
Case 1
' rechtsbündig
.CurrentX = xPos + MaxWidth - .TextWidth(sLine(I))
Case 2
' zentriert
.CurrentX = xPos + (MaxWidth - .TextWidth(sLine(I))) / 2
Case Else
' linksbündig
.CurrentX = xPos
End Select
Printer.Print sLine(I)
Else
' Zeile umbrechen
Do
NextLine = ""
While .TextWidth(sLine(I)) > MaxWidth
NextLine = Right$(sLine(I), 1) + NextLine
sLine(I) = Left$(sLine(I), Len(sLine(I)) - 1)
Wend
' Wortumbruch prüfen
CheckUmbruch NextLine, sLine(I)
' wenn nicht mehr ins Rechteck (maxHeight)
' passt, Prozedur verlassen
If Not CheckTextHeight(sLine(I), .CurrentY, _
y2, MaxHeight, sUmbruch) Then Exit Sub
' Ausrichtung
Select Case tAlign
Case 1
' rechtsbündig
.CurrentX = xPos + MaxWidth - .TextWidth(sLine(I))
Case 2
' zentriert
.CurrentX = xPos + (MaxWidth - .TextWidth(sLine(I))) / 2
Case Else
' linksbündig
.CurrentX = xPos
End Select
Printer.Print sLine(I)
sLine(I) = NextLine
Loop Until Trim$(sLine(I)) = ""
End If
Next I
End With
End Sub Würde mich über hilfe freuen.
Mfg. Crysis |