Cette extension génère des constructeurs VB, des getters/setters, une liste d'attributs de classe (avec types et valeurs de format de sortie) et des usines singleton à partir des déclarations de variables de classe VB. Vous pouvez également les restituer tous en une seule commande ! :)
Sélectionnez les attributs pour lesquels vous souhaitez générer un extrait et exécutez l'une des commandes suivantes sur la palette de commandes 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. Attribut Private Const (nécessite le mot-clé Const et l'attribution à la fin) :
Private Const p_attr As String = "ATTRIBUTE"2. Formatage des cas de cellule (nécessite les mots-clés FORMAT et VALUE , ainsi que NumberFormat ou NumberFormatLocal comme types de propriété de format d'un objet Range dans VBA) :
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. Formatage des couleurs des cellules (nécessite les mots-clés FORMATCOLOR , BGCOLOR et FGCOLOR , ainsi que des valeurs numériques pour la couleur d'arrière-plan - 0 à 56 - et des couleurs constantes VB pour la couleur de premier plan - vbWhite, vbRed, vbBlack, etc.) :
' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack4. Les cas de cellules de formatage peuvent être combinés (type de format et couleurs) :
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. Le format numérique peut également être utilisé avec un attribut Const :
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. Dans le cas où vous ne dites pas quel est le type de l'attribut, l'extension comprendra dans tous les générateurs que l'attribut est de type Variant , par exemple :
Private p_attr As
Private p_attr7. Les cas suivants génèrent des erreurs, alors évitez-les à tout prix :
' *** 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. Les cas d'usine afficheront le fichier (si aucune erreur n'est émise ou s'il y a au moins un attribut non constant) dans un dossier Factories/. Il peut vous être demandé d'approuver un remplacement si le fichier d'usine spécifique existe déjà dans le dossier.
L'idée principale d'avoir une liste d'attributs avec leur format de sortie respectif est de faciliter la sortie de chaque valeur d'attribut dans une ligne de feuille. Le Sub suivant utilise la liste et leurs formats respectifs pour parcourir un objet et afficher toutes les valeurs d'attributs dans une ligne :
'*******************************************
'*** @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
N'hésitez pas à m'envoyer un PR ou un problème pour améliorer le code :)