Esta extensión genera constructores, captadores/definidores de VB, lista de atributos de clase (con tipos y valores de formato de salida) y fábricas singleton a partir de las declaraciones de variables de clase de VB. ¡También puedes renderizarlos todos con un solo comando! :)
Seleccione los atributos que desea generar un fragmento y ejecute uno de los siguientes comandos en la paleta de comandos 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. Atributo Const privado (necesita la palabra clave Const y la atribución al final):
Private Const p_attr As String = "ATTRIBUTE"2. Formatear casos de celda (necesita las palabras clave FORMAT y VALUE , así como NumberFormat o NumberFormatLocal como tipos de propiedad de formato de un objeto Range en VBA):
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. Formatear los colores de las celdas (necesita las palabras clave FORMATCOLOR , BGCOLOR y FGCOLOR , así como valores numéricos para el color de fondo (0 a 56) y colores constantes VB para el color de primer plano (vbWhite, vbRed, vbBlack, etc.):
' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack4. Se pueden combinar formatos de cajas de celdas (tipo de formato y colores):
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. El formato numérico también se puede utilizar con un atributo 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. En caso de que no digas cuál es el tipo del atributo, la extensión entenderá en todos los generadores que el atributo es de tipo Variante , por ejemplo:
Private p_attr As
Private p_attr7. Los siguientes casos generarán errores, así que evítelos a toda costa:
' *** 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. Los casos de fábrica generarán el archivo (si no se emiten errores o hay al menos un atributo no constante) en una carpeta Fábricas/. Es posible que se le solicite que apruebe una anulación en caso de que el archivo de fábrica específico ya exista en la carpeta.
La idea principal de tener una lista de atributos con su respectivo formato de salida es facilitar la salida de cada valor de atributo en una fila de Hoja. El siguiente Sub utiliza la lista y sus respectivos formatos para iterar a través de un objeto y generar todos los valores de los atributos en una fila:
'*******************************************
'*** @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
No dudes en enviarme un PR o un problema para mejorar el código :)