X-VBA

Version 1.2.0

JSON Documentation


VBA Code

XDocGen

XDocGen is a VBA utility program used to generate documentation from your VBA code. It takes VBA source code and returns JSON with relevant features from the code. Additionally, it uses a tag language that can be used to generate documentation as well. The source code for XDocGen can be found at the official github page.

As an example of JSON generated from XDocGen, below is an example of VBA source code and JSON documentation generated from it:

VBA Code
'@Module: This module contains a function for adding two numbers

Public Function ADD_TWO( _
	ByVal intA As Integer, _
	ByVal intB As Integer) _
As Integer

	'@Description: This function adds two integers together
	'@Param: intA is the first integer
	'@Param: intB is the second integer
	'@Returns: Returns the sum of both integers
	'@Example: =ADD_TWO(5, 10) -> 15
	
	ADD_TWO = intA + intB
	
End Function

JSON Generated Documentation
{
  "Module": {
    "Module": "This module contains a function for adding two numbers"
  },
  "Procedures": [
    {
      "Name": "ADD_TWO",
      "Scope": "Public",
      "Static": false,
      "Procedure": "Function",
      "Type": "Integer",
      "Description": "This function adds two integers together",
      "Param": [
        {
          "Name": "intA",
          "Optional": false,
          "Passing": "ByVal",
          "ParamArray": false,
          "Type": "Integer",
          "Array": false,
          "Default": null,
          "Description": "is the first integer"
        },
        {
          "Name": "intB",
          "Optional": false,
          "Passing": "ByVal",
          "ParamArray": false,
          "Type": "Integer",
          "Array": false,
          "Default": null,
          "Description": "is the second integer"
        }
      ],
      "Returns": "Returns the sum of both integers",
      "Example": "=ADD_TWO(5, 10) -> 15"
    }
  ]
}

XDocTag Syntax

XDocGen is very flexible in terms of what tags you can use. Before getting into the syntax, note that XDocGen uses two different types of tags based on Scope:

  1. Module Level Tags

    These are tags declared outside of a Sub or Function. Generally they can be placed anywhere within the code, but the preferred approach is at the top of the Module. In the JSON generated documentation, these will be included within the "Module" section.

  2. Procedure Level Tags

    These are tags declared inside of a Sub or Function. In the JSON generated documentation, these will be included within the "Procedures" section.

XDocGen tags take the form of the following:

'@TagName: Tag details

All tags are within a comment, start with and "@" symbol and then the name of the tag, following by a ":", a space, and then the description of the tag. If you follow this syntax, it will be a valid tag.

Note that XDocGen does not have a required set of tags, except for one special tag, @Param. You can use any tag names you want. However, I recommend the following tags:

Name Description
@Description The Description of the Function or Sub
@Author The Author of the Function or Sub
@License The License of the Function or Sub
@Param A single parameter of the Function or Sub
@Returns The value returned by the Function or Sub
@Example An example of the Function or Sub
@Credits Anyone else creditted
@Todo Any additional features to be added
@Note Any notes that users of the function should know
@Warning Any warnings that users of the function should know

The @Param Tag

The @Param Tag is the only special tag within XDocGen. Since VBA is a strongly typed language, details of the Parameters are included within the Function or Sub declaration. As a result, XDocGen will match the Parameters in the @Param tag with details in the procedure declaration. The syntax for the @Param tag is:

'@Param: parameterName parameter details

You need to put the name of the parameter as the first word after the ":" of the tag, and then a space, followed by the details. The first word must be the name of the paramter!. If you follow the syntax, all of the details of the Parameter will be included in the JSON documentation.

Multiple Tags

Because XDocGen does not generally have any required tags, you can use tags multiple times. If you use a tag multiple times, within the JSON generated documentation the tag will contain and array of details from the tags. For example, if you use a single @Example tag, the JSON generated will be:

VBA Code
'@Example: =ADD_TWO(5, 10) -> 15

JSON Generated Documentation
"Example": "=ADD_TWO(5, 10) -> 15"

Where as if you use 2 @Example tags:

VBA Code
'@Example: =ADD_TWO(5, 10) -> 15
'@Example: =ADD_TWO(3, 4) -> 7

JSON Generated Documentation
"Example": ["=ADD_TWO(5, 10) -> 15", "=ADD_TWO(3, 4) -> 7"]

Where does my code go?

XMinifier and XCombiner are written in pure JavaScript, which means they can be shipped and run in the web browser. Both programs are embedded in this web page and are run purely locally. No code is shipped to a server elsewhere, all of your code remains purely on your machine. In fact, the only web request ever used is the one to fetch this webpage. No external JavaScript files or libraries are used on this web page, nor are any images or CSS files. As a result, this single page can be saved and run offline whenever you need to combine or minify your VBA code. And since it runs offline, you can rest assure that your code remains purely with you and isn't ever sent to a server.

License

The MIT License (MIT)

Copyright © 2020 Anthony Mancini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.