Esta extensão gera construtores VB, getters/setters, lista de atributos de classe (com tipos e valores de formato de saída) e fábricas singleton a partir das declarações de variáveis de classe VB. Você também pode renderizar todos eles em um único comando! :)
Selecione os atributos que deseja gerar um snippet e execute um dos seguintes comandos na 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 (precisa da palavra-chave Const e da atribuição no final):
Private Const p_attr As String = "ATTRIBUTE"2. Formatação de casos de células (precisa das palavras-chave FORMAT e VALUE , bem como NumberFormat ou NumberFormatLocal como tipos de propriedade de formato de um objeto Range em VBA):
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. Formatação de cores de células (precisa das palavras-chave FORMATCOLOR , BGCOLOR e FGCOLOR , bem como valores numéricos para cor de fundo - 0 a 56 - e cores constantes VB para cor de primeiro 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. A formatação dos casos de células pode ser combinada (tipo de formato e cores):
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. O formato numérico também pode ser usado com um 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. Caso você não informe qual é o tipo do atributo, a extensão entenderá em todos os geradores que o atributo é do tipo Variant , por exemplo:
Private p_attr As
Private p_attr7. Os seguintes casos produzirão erros, portanto evite-os a todo custo:
' *** 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. Os casos de fábrica produzirão o arquivo (se nenhum erro for emitido ou se houver pelo menos um atributo não constante) em uma pasta Factories/. Você pode ser solicitado a aprovar uma substituição caso o arquivo de fábrica específico já exista na pasta.
A ideia principal de ter uma lista de atributos com seu respectivo formato de saída é facilitar a saída de cada valor de atributo em uma linha da planilha. O seguinte Sub usa a lista e seus respectivos formatos para iterar através de um objeto e gerar todos os valores dos atributos em uma linha:
'*******************************************
'*** @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
Sinta-se à vontade para me enviar um PR ou um problema para melhorar o código :)