'WordWrap 2 'make a new project with a form (name = frmWordWrap) 'one textbox (name = text1) 'two labels with an index (name = label1(0) & label1(1) 'two textboxes with an index (name = text2(0) & text2(1) 'a command button (name = command1) 'insert the code 'press F5 Option Explicit Dim intLMReturnas
Integer Dim intMaxLengthas
Integer Privatesub
Command1_Click() Printer.ScaleMode = vbMillimeters Printer.Scale (0, 0)-(210, 290) Call PrintExample Printer.EndDoc End Sub Privatesub
Form_Load()dim
strDummyas
String strDummy = "wie weet waar willemwouter
woont?" & vbCrLf strDummy = strDummy + "willemwouter
woont
weit weg." Text1.Text = strDummy Text2(0).Text = "15" Text2(1).Text = "20" End Sub Privatesub
PrintExample() intLM = CInt(Text2(0).Text) intMaxLength = CInt(Text2(1).Text) Printer.CurrentX = intLM Call CheckLine(Text1.Text) End Sub Publicsub
Wrap(sourceas
String)dim
intCounteras
Integerdim
strPartas
Stringdim
intTelleras
Integer intCounter = 1 Do While intCounter < Len(source) strPart = Mid$(source, intCounter, intMaxLength) If intCounter + Len(strPart) < Len(source) Then For intTeller = Len(strPart) To 1 Step -1 If Mid$(strPart, intTeller, 1) = Chr(32) Then Printer.CurrentX = intLM Printer.Print Mid$(source, intCounter, intTeller) intCounter = intCounter + intTeller intTeller = 1end
If Next intTeller Else Printer.CurrentX = intLM Printer.Print strPart intCounter = Len(source)end
If Printer.CurrentX = intLM Loop End Sub Publicsub
CheckLine(sourceas
String)dim
positiedim
intLenghtas
Integerdim
intCounteras
Integerdim
strDummyas
String intLenght = Len(source) strDummy = source 'vanaf eerste teken tot aan het laatste teken For intCounter = 1 To intLenght 'als teken is harde return If Mid$(strDummy, intCounter, 1) = Chr(10) Then If Len(Mid$(strDummy, 1, intCounter - 2)) > intMaxLength Then Call Wrap(Mid$(strDummy, 1, intCounter - 2)) Else Printer.CurrentX = intLM Printer.Print Mid$(strDummy, 1, intCounter - 2)end
If strDummy = Right$(strDummy, intLenght - intCounter) intCounter = 1 intLenght = Len(strDummy)end
If Next intCounter If Len(strDummy) > intMaxLength Then Call Wrap(strDummy) Else Printer.CurrentX = intLM Printer.Print strDummyend
If End Sub