Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Applications VBA Code Examples

Making wordwrap in code

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
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