This is an old revision of the document!
Das Gegenteil von Trim. lPad und rPad erweitern Strings auf eine bestimmte Länge. Diese Version schneidet zu lange Strings auch ab.
Für die Ausgabe der Resultate verwendete ich die Funktion [VBA] print_r().
d lpad("ab", 4) <String> 'ab ' d lpad("Zürich", 4) <String> 'Züri' d rpad("Bern", 6, "_") <String> '__Bern' d rpad(123, 6, 0) <String> '000123'
Attribute VB_Name = "lib_increment" '------------------------------------------------------------------------------- 'File : lib_increment.bas ' Copyright mpl by ERB software ' All rights reserved ' http://wiki.yaslaw.info/dokuwiki/doku.php/vba/functions/increment 'Environment : VBA 2007 + 'Version : 1.1.0 'Name : lib_increment 'Author : Stefan Erb (ERS) 'History : 25.11.2014 - ERS - Creation ' 11.01.2016 - ERS - inc() verkürzt '------------------------------------------------------------------------------- Option Explicit Public Enum incType itPreIncrement = 0 '++1 itPostIncrement = 1 'i++ itPreDecrement = 2 '--i itPostDecrement = 3 'i-- End Enum '/** ' * @param Number ' * @param incType Type der Encrementation. Default ist i++ ' * @retrun Number '*/ Public Function inc(ByRef i As Variant, Optional ByVal iIncType As incType = itPreIncrement) As Variant Select Case iIncType Case itPreIncrement: i = i + 1: inc = i '++i Case itPostIncrement: inc = i: i = i + 1 'i++ Case itPreDecrement: i = i - 1: inc = i '--i Case itPostDecrement: inc = i: i = i - 1 'i-- End Select End Function '/** ' * PreIncrement ++i ' * Zählt i eins hoch und gibt den Wert zurück ' * @param Number ' * @retrun Number '*/ Public Function preInc(ByRef i As Variant) As Variant: preInc = inc(i, itPreIncrement): End Function '/** ' * PostIncrement i++ ' * Gibt den Wert zurück und zählt dann i eins hoch ' * @param Number ' * @retrun Number '*/ Public Function postInc(ByRef i As Variant) As Variant: postInc = inc(i, itPostIncrement): End Function '/** ' * PreDecrement --i ' * Zählt i eins hoch und gibt den Wert zurück ' * @param Number ' * @retrun Number '*/ Public Function preDec(ByRef i As Variant) As Variant: preDec = inc(i, itPreDecrement): End Function '/** ' * PostDecrement i-- ' * Gibt den Wert zurück und zählt dann i eins hoch ' * @param Number ' * @retrun Number '*/ Public Function postDec(ByRef i As Variant) As Variant: postDec = inc(i, itPostDecrement): End Function