Diese Erweiterung generiert VB-Konstruktoren, Getter/Setter, Klassenattributlisten (mit Ausgabeformattypen und -werten) und Singleton-Factorys aus den VB-Klassenvariablendeklarationen. Sie können sie auch alle in einem einzigen Befehl rendern! :) :)
Wählen Sie die Attribute aus, für die Sie ein Snippet generieren möchten, und führen Sie einen der folgenden Befehle auf der Befehlspalette aus: Ctrl/Cmd + Shift + P :
$ VB getters and setters
$ VB constructor
$ VB class attribute list
$ VB class attribute list with output format list
$ VB factory from class attributes
$ VB full class
$ VB full class with factory
1. Privates Const-Attribut (benötigt das Const -Schlüsselwort und die Namensnennung am Ende):
Private Const p_attr As String = "ATTRIBUTE"2. Zellenfälle formatieren (benötigt die Schlüsselwörter FORMAT und VALUE sowie NumberFormat oder NumberFormatLocal als Formateigenschaftstypen eines Range-Objekts in VBA):
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. Zellfarben formatieren (erfordert die Schlüsselwörter FORMATCOLOR , BGCOLOR und FGCOLOR sowie numerische Werte für die Hintergrundfarbe (0 bis 56) und konstante VB-Farben für die Vordergrundfarbe (vbWhite, vbRed, vbBlack usw.):
' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack4. Die Formatierung von Zellgehäusen ist kombinierbar (Formattyp und Farben):
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. Das Zahlenformat kann auch mit einem Const -Attribut verwendet werden:
Private Const p_attr As String = "ATTRIBUTE" ' FORMAT NumberFormat VALUE @
Private Const p_attr As String = "ATTRIBUTE" ' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
Private Const p_attr As String = "ATTRIBUTE" ' FORMAT NumberFormat VALUE @ FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack6. Falls Sie nicht angeben, welcher Typ das Attribut ist, erkennt die Erweiterung in allen Generatoren, dass das Attribut ein Variant- Typ ist, zum Beispiel:
Private p_attr As
Private p_attr7. In den folgenden Fällen werden Fehler ausgegeben. Vermeiden Sie diese daher unbedingt:
' *** No Public/Private declaration
p_attr As String
' *** No attribution from Const attribute
Private Const p_attr
Private Const p_attr As String = ""
' *** Const attribute with the Const keyword
Private p_attr As String
' *** FORMET instead of FORMAT, TextFormat not acceptable, VALUES instead of VALUE, " usages are not allowed in the format value
Private p_attr As String ' FORMET TextFormat VALUES "@"
' *** FORMETCOLOUR instead of FORMATCOLOR, BG_COLOR instead of BGCOLOR, vbblack instead vbBlack, " usages are not allowed in the BGCOLOR value (needs to be numeric)
Private p_attr As String ' FORMETCOLOUR BG_COLOR "1" FG_COLOR vbblack
' *** BGCOLOR and FGCOLOR without values
Private p_attr As String ' FORMATCOLOR BGCOLOR FGCOLOR
' *** BGCOLOR and FGCOLOR inverted positions, BGCOLOR value out of range (0-56)
Private p_attr As String ' FORMATCOLOR FGCOLOR vbBlack BGCOLOR 578. Factory Cases geben die Datei (wenn keine Fehler ausgegeben werden oder mindestens ein nicht konstantes Attribut vorhanden ist) in einem Factories/-Ordner aus. Möglicherweise werden Sie aufgefordert, eine Außerkraftsetzung zu genehmigen, falls die spezifische Factory-Datei bereits im Ordner vorhanden ist.
Der Hauptgedanke einer Attributliste mit ihrer jeweiligen Formatausgabe besteht darin, die Ausgabe jedes Attributwerts in einer Tabellenzeile zu vereinfachen. Das folgende Sub verwendet die Liste und ihre jeweiligen Formate, um ein Objekt zu durchlaufen und alle Attributwerte in einer Zeile auszugeben:
'*******************************************
'*** @Sub insertGenericRow *****************
'*******************************************
'*** @Argument {Worksheet} ws **************
'*** @Argument {Variant} classObj **********
'*** @Argument {Integer} myLL **************
'*******************************************
'*** Insert a header/shipment/charge *******
'*** inside a worksheet. *******************
'*******************************************
Sub insertGenericRow(ws As Worksheet, classObj As Variant , ByRef myLL As Integer )
Dim listLen As Integer
Dim i As Integer
i = 1
listLen = UBound(classObj.attributesList)
' Iterate through each ordered property from class and send it to the iterated cell with formats
With ws
For i = 0 To listLen
If Not (isEmpty(classObj.attributesFormatTypesList()(i))) Then
If classObj.attributesFormatTypesList()(i) = "NumberFormat" Then
If Not (isEmpty(classObj.attributesFormatValuesList()(i))) Then
.Cells(myLL, i + 1 ).NumberFormat = classObj.attributesFormatValuesList()(i)
End If
End If
End If
' classObj.attributesList() returns the list, and then classObj.attributesList()(i) access an i-element of the list
.Cells(myLL, i + 1 ).value = CallByName(classObj, classObj.attributesList()(i), VbGet)
' Format cell after inserting into sheet
If Not (isEmpty(classObj.attributesFormatTypesList()(i))) Then
If classObj.attributesFormatTypesList()(i) = "NumberFormat" Then
If Not (isEmpty(classObj.attributesFormatValuesList()(i))) Then
.Cells(myLL, i + 1 ).NumberFormat = classObj.attributesFormatValuesList()(i)
End If
End If
End If
Next
End With
myLL = myLL + 1
End Sub MIT © davikawasaki
Schicken Sie mir gerne eine PR oder ein Problem, um den Code zu verbessern :)