Visual Basic > Applications-VBA
Making wordwrap in code
Making wordwrap in code '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 intLM as Integer Dim intMaxLength as Integer Private sub Command1_Click() Printer.ScaleMode = vbMillimeters Printer.Scale (0, 0)-(210, 290) Call PrintExample Printer.EndDoc End Sub Private sub Form_Load() dim strDummy as String strDummy = "wie weet waar willem wouter woont?" & vbCrLf strDummy = strDummy + "willem wouter woont weit weg." Text1.Text = strDummy Text2(0).Text = "15" Text2(1).Text = "20" End Sub Private sub PrintExample() intLM = CInt(Text2(0).Text) intMaxLength = CInt(Text2(1).Text) Printer.CurrentX = intLM Call CheckLine(Text1.Text) End Sub Public sub Wrap(source as String) dim intCounter as Integer dim strPart as String dim intTeller as 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 = 1 end If Next intTeller Else Printer.CurrentX = intLM Printer.Print strPart intCounter = Len(source) end If Printer.CurrentX = intLM Loop End Sub Public sub CheckLine(source as String) dim positie dim intLenght as Integer dim intCounter as Integer dim strDummy as 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 strDummy end If End Sub Return
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows