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 或改進程式碼的問題:)