vb vscode generators
1.0.0
此扩展从 VB 类变量声明生成 VB 构造函数、getters/setters、类属性列表(具有输出格式类型和值)和单例工厂。您也可以通过一个命令来渲染它们! :)
选择要生成代码片段的属性,然后在命令面板上运行以下命令之一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.私有Const属性(需要Const关键字和最后的属性):
Private Const p_attr As String = "ATTRIBUTE"2. 格式化单元格大小写(需要FORMAT和VALUE关键字,以及NumberFormat或NumberFormatLocal作为 VBA 中 Range 对象的格式属性类型):
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. 设置单元格颜色的格式(需要FORMATCOLOR 、 BGCOLOR和FGCOLOR关键字,以及背景颜色的数值 - 0 到 56 - 以及前景色的 VB 常量颜色 - vbWhite、vbRed、vbBlack 等):
' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack4. 可以组合格式化单元格大小写(格式类型和颜色):
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. 数字格式也可以与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. 如果您没有说明属性的类型,则扩展将在所有生成器中理解该属性是Variant类型,例如:
Private p_attr As
Private p_attr7. 以下情况会输出错误,所以一定要避免:
' *** 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 案例将在 Factories/ 文件夹中输出文件(如果没有发出错误或至少有一个非常量属性)。如果文件夹中已存在特定的工厂文件,则可能会要求您批准覆盖。
拥有具有各自格式输出的属性列表的主要思想是可以轻松地将每个属性值输出到工作表行中。以下 Sub 使用列表及其各自的格式来迭代对象并将所有属性值输出到一行中:
'*******************************************
'*** @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 麻省理工学院©davikawasaki
请随时向我发送 PR 或改进代码的问题:)