Git Product home page Git Product logo

vb-vscode-generators's Introduction

VB Generators

Extension for Visual Studio Code

This extension generate VB constructors, getters/setters, class attributes list (with output format types and values) and singleton factories from the VB class variable declarations. You can render them all in a single command too! :)

Marketplace Version Installs Rating

Table of contents

Usage

Select the attributes that you want to generate a snippet and run one of the following commands on the command pallete 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

Attributes Structure Recommendations

1. Private Const Attribute (needs the Const keyword and the attribution in the end):

Private Const p_attr As String = "ATTRIBUTE"

2. Formatting cell cases (needs the FORMAT and VALUE keywords, as well as NumberFormat or NumberFormatLocal as format-property types of a Range object in VBA):

 ' FORMAT NumberFormat VALUE @ 
 ' FORMAT NumberFormat VALUE yyyy-mm-dd
 ' FORMAT NumberFormat VALUE #####0.#0

3. Formatting cell colors (needs the FORMATCOLOR, BGCOLOR and FGCOLOR keywords, as well as numeric values for background color - 0 to 56 - and VB constant colors for foreground color - vbWhite, vbRed, vbBlack, etc):

 ' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
 ' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
 ' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack

4. Formatting cell cases can be combined (format type and colors):

 ' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack

5. The number format can be used with a Const attribute as well:

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 vbBlack

6. In case you do not say which is the type of the attribute, the extension will understand in all generators that the attribute is a Variant type, for instance:

Private p_attr As
Private p_attr

7. The following cases will output errors, so avoid them at all costs:

' *** 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 57

8. Factory cases will output the file (if no errors are emitted or there are at least one non-constant attribute) in a Factories/ folder. You may be enquired to approve an override in case the specific factory file already exists in the folder.

Attribute list with format output

The main idea of having an attribute list with their respective format output is to make it easy to output each attribute value into a Sheet row. The following Sub uses the list and their respective formats to iterate through an object and output all the attributes values into a row:

'*******************************************
'*** @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

Examples

Rendering Class Constructor

how use

Rendering Attributes Getters and Setters

how use

Rendering Attributes List with class initialization

how use

Rendering Attributes List with class initialization and output formats

how use

Rendering Singleton Factory from Class Attributes

how use

Full Rendering Process

how use

Full Rendering Process with Factory

how use

Authors and Collaborators

  • Davi Kawasaki

Inspirations

License

MIT © davikawasaki

Contribution

Feel free to send me a PR or an issue to improve the code :)

vb-vscode-generators's People

Contributors

davikawasaki avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.