Predefined Variables

Top  Previous  Next

 VS   VB6   VBA 

Predefined variables are variables used in code templates, exception / error handlers, headers, etc. whose values are assigned automatically by MZ-Tools when the code template is inserted into the code file (on the contrary to user-defined variables, whose values are asked to the user through a dialog window).

Predefined variables are created using the Insert > Predefined variable... button, which shows this dialog window, where you select the predefined variable:

PredefinedVariables

The predefined variables provided by MZ-Tools to be used in templates are specified below. Note that not all the predefined variables are supported in every kind of template or IDE:

  • Selected Text ($P[SELECTED_TEXT]): the text currently selected in the document. This variable is useful to enclose the selected text with some code above and below. For example, to add an exception / error handler to selected code.
  • Comment Prefix ($P[COMMENT_PREFIX]): the prefix that the language of the document uses to comment lines. For example, C# uses the // prefix while VB.NET / VB / VBA uses the ' prefix. This variable is useful to create templates with comments that can be used by documents in several languages.
  • XML Comment Prefix ($P[XML_COMMENT_PREFIX]): the prefix that the .NET language of the document uses for XML comments. For example, C# uses the /// prefix while VB.NET uses the ''' prefix. This variable is useful to create templates with XML comments that can be used by documents in several .NET languages.
  • Guid ($P[GUID]): a new generated Guid.
  • Author ($P[AUTHOR]): the user who is inserting the template. You can customize in the Options window, Personal Options tab, General section, whether you want to use the Windows username or a specific username.
  • Company ($P[COMPANY]): the name of your company. You can customize its value in the Options window, Team Options tab, General section.
  • Assembly Version ($P[ASSEMBLY_VERSION]): for Visual Studio projects, this is the value of the AssemblyVersion attribute specified in the AssemblyInfo file of the project, and it represents the version of the assembly. In .NET, assemblies have an assembly file version and an assembly version.
  • Assembly File Version ($P[ASSEMBLY_FILE_VERSION]): for Visual Studio projects, this is the value of the AssemblyFileVersion attribute specified in the AssemblyInfo file of the project, and it represents the version of the file of assembly (not to be confused with the version of the assembly).
  • Date ($P[DATE]): the current date. You can customize the format in the Options window, Team Options tab, General section.
  • Time ($P[TIME]): the current time. The format is always "HH:mm" and can not be customized.
  • Year ($P[YEAR]): the current year (useful for copyrights). The format is always "yyyy" and can not be customized.
  • Cursor Position After Insertion ($P[I]): this variable is not replaced by an actual value but it allows you to specify where the text cursor (the caret) should be positioned after the template is inserted in the document.
  • Solution Name ($P[SOLUTION_NAME]) or Project Group Name ($[PROJECT_GROUP_NAME]): the name of the solution or project group (the file name without the extension).
  • Solution File Name ($P[SOLUTION_FILENAME]) or Project Group File Name ($[PROJECT_GROUP_FILE_NAME]): the name without path of the file of the solution or project group.
  • Solution File Name With Path ($P[SOLUTION_FILENAME_WITH_PATH]) or Project Group File Name With Path ($[PROJECT_GROUP_FILE_NAME_WITH_PATH]): the name with path of the file of the solution or project group.
  • Solution Folder ($P[SOLUTION_FOLDER]) or Project Group Folder ($[PROJECT_GROUP_FOLDER]): the path of the folder of the solution or project group.
  • Project Name ($P[PROJECT_NAME]): the name of the project of the document where the template is being inserted (for Visual Studio it's the file name without the extension).
  • Project File Name ($P[PROJECT_FILENAME]): the name without path of the file of the project of the document where the template is being inserted.
  • Project File Name With Path ($P[PROJECT_FILENAME_WITH_PATH]): the name with path of the file of the project of the document where the template is being inserted.
  • Project File Extension ($P[PROJECT_FILEEXT]): the extension of the file of the project of the document where the template is being inserted.
  • Project Folder ($P[PROJECT_FOLDER]): the folder of the project of the document where the template is being inserted.
  • Project Item File Name ($P[PROJECT_ITEM_FILENAME]): the name without path of the file of the document where the template is being inserted.
  • Project Item File Name With Path ($P[PROJECT_ITEM_FILENAME_WITH_PATH]): the name with path of the file of the document where the template is being inserted.
  • Project Item File Extension ($P[PROJECT_ITEM_FILEEXT]): the extension of the file of the document where the template is being inserted.
  • Project Item Folder ($P[PROJECT_ITEM_FOLDER]): the folder of the file of the document where the template is being inserted.
  • Project Item Kind ($P[PROJECT_ITEM_KIND]): the kind of the file. For example, for .NET: "Form", "UserControl", "Code", etc. For VB/VBA: "Class", "Form", "Module", "Class Module", "UserControl", "UserDocument", "Property Page", "Designer", etc.
  • Code Element Full Name ($P[CODE_ELEMENT_FULL_NAME]): the full name (with namespace or library name) of the code element where the template is being inserted. For example, "Vehicles.Car".
  • Code Element Name ($P[CODE_ELEMENT_NAME]): the name (without namespace) of the code element where the template is being inserted. For example, "Car".
  • Code Element Declaration ($P[CODE_ELEMENT_DECLARATION]): the declaration of the code element where the template is being inserted. For example, "public int f1()".
  • Code Element Kind Description ($P[CODE_ELEMENT_KIND_DESCRIPTION]): the description of the code element where the template is being inserted. For example, "Class", "Namespace", etc.
  • Code Element Kind Keyword ($P[CODE_ELEMENT_KIND_KEYWORD]): the keyword for the kind of the code element where the template is being inserted. For example, "struct" for C#, "Structure" for VB.NET, "Type" for VB, etc.
  • Code Element Access Keyword ($P[CODE_ELEMENT_ACCESS_KEYWORD]): the keyword for the visibility of the code element. For example, "Public", "Private", etc.
  • Method Body Including Declarations ($P[METHOD_BODY]): the body of the method where the template is being inserted, including method constants and variables. This variable is useful to insert custom code at the start / end of a method, or for exception / error handlers.
  • Method Body Excluding Declarations ($P[METHOD_BODY_EXCLUDING_DECLARATIONS]): the body of the method where the template is being inserted, excluding method constants and variables. This variable is only available for VB6/VBA and is useful for error handlers. In VB, variable declarations that create instances with the New operator (ex: Dim myCar As New Car) cannot execute code (instances are created when the variable is actually used) and therefore can be excluded from the error handler. In .NET they can execute code since the instance is created when the variable is declared.
  • Method Handled Events ($P[METHOD_HANDLED_EVENTS]) (only VB.NET): the list of handled events (after the "Handles" clause of the method declaration).
  • Method Return Section Begin ($P[METHOD_RETURN_SECTION_BEGIN]): delimiter of the begin of a section that will be used for information about the return type of a method. It is useful to include that information inside a section because the whole section is deleted if the method doesn't return a value ("void" in C#, "Sub" in Visual Basic), so you can share the same header for methods that return values and methods that don't.
  • Method Return Section End ($P[METHOD_RETURN_SECTION_END]): delimiter of the end of a section that will be used for information about the return type of a method. It is used along with the previous one.
  • Method Return Type Name ($P[METHOD_RETURN_TYPE_NAME]): the name of the type that the method returns, using the .NET Framework name. For example, "Int32".
  • Method Return Type Full Name ($P[METHOD_RETURN_TYPE_FULL_NAME]): the full name of the type that the method returns. For example, "System.Int32".
  • Method Return Type Aliased Name ($P[METHOD_RETURN_TYPE_ALIASED_NAME]): the alias in the .NET language of the document for the type that the method returns. For example, "int" in the case of C# or "Integer" in the case of VB.NET.
  • Method Return Type Prefix ($P[METHOD_RETURN_TYPE_PREFIX]): the prefix defined in the Options window, Team Options tab, Type Tags section (see Type Tags Options) for the type that the method returns.
  • Method Property Kind ($P[METHOD_PROPERTY_KIND]): the kind of property, such as "Get", "Set", "Let" for Visual Basic and "get" or "set" for C#.
  • Parameter Section Begin ($P[PARAMETER_SECTION_BEGIN]): delimiter of the begin of the section that will be repeated for each parameter.
  • Parameter Section End ($P[PARAMETER_SECTION_END]): delimiter of the end of the section that will be repeated for each parameter. It is used along with the previous one.
  • Parameter Name ($P[PARAMETER_NAME]): the name of the parameter of the method, delegate, etc.. One line is generated for each parameter unless the Parameter Section Begin and Parameter Section End predefined variables are used.
  • Parameter Type Full Name ($P[PARAMETER_TYPE_FULL_NAME]): the full name of the type of the parameter. For example, "System.Int32".
  • Parameter Type Name ($P[PARAMETER_TYPE_NAME]): the name of the type of the parameter, using the .NET Framework name. For example, "Int32".
  • Parameter Type Aliased Name ($P[PARAMETER_TYPE_ALIASED_NAME]): the alias in the .NET language of the document for the type of the parameter. For example, "int" in the case of C# or "Integer" in the case of VB.NET.
  • Parameter Modifiers ($P[PARAMETER_MODIFIERS]): the modifiers of the parameter. For example, "ref", "out", etc. for C# or "ByVal", "ByRef", "Optional", etc. for VB.NET.
  • Parameter Default Value ($P[PARAMETER_DEFAULT_VALUE]): the default value of an optional parameter.
  • Parameter Padding ($P[PARAMETER_PADDING]): since normally one line is generated for each parameter, this variable allows you to align the descriptions of the parameters after the names.
  • Parameter Separator (Comma) ($P[PARAMETER_COMMA_SEPARATOR]): the comma character "," if the parameter is not the last one, or the empty character "" if it is the last one. This variable is typically used to build a comma-separated list of parameters in a single line.
  • Parameter Separator (Space) ($P[PARAMETER_SPACE_SEPARATOR]): the space character " " if the parameter is not the last one, or the empty character "" if it is the last one. This variable is typically used to build a comma-separated list of parameters in a single line.
  • Generic Type Parameter Section Begin ($P[GENERIC_TYPE_PARAMETER_SECTION_BEGIN]): delimiter of the begin of the section that will be repeated for each type parameter of a generic declaration.
  • Generic Type Parameter Section End ($P[GENERIC_TYPE_PARAMETER_SECTION_END]): delimiter of the end of the section that will be repeated for each type parameter of a generic declaration. It is used along with the previous one.
  • Generic Type Parameter Name ($P[GENERIC_TYPE_PARAMETER_NAME]): the name of each type parameter of a generic declaration. One line is generated for each parameter unless the Parameter Section Begin and Parameter Section End predefined variables are used.
  • Generic Type Parameter Padding ($P[GENERIC_TYPE_PARAMETER_PADDING]): since normally one line is generated for each generic type parameter, this variable allows you to align the descriptions of the generic type parameters after the names.
  • Generic Type Parameter Separator (Comma) ($P[GENERIC_TYPE_PARAMETER_COMMA_SEPARATOR]): the comma character "," if the generic type parameter is not the last one, or the empty character "" if it is the last one. This variable is typically used to build a comma-separated list of generic type parameters in a single line.
  • Generic Type Parameter Separator (Space) ($P[GENERIC_TYPE_PARAMETER_SPACE_SEPARATOR]): the space character " " if the generic type parameter is not the last one, or the empty character "" if it is the last one. This variable is typically used to build a comma-separated list of generic type parameters in a single line.
  • Control Tag (custom) ($P[COMPONENT_CUSTOM_TAG]): the custom tag of the control defined in the Control Tag Options. For example, "btn" for the System.Windows.Forms.Button control.
  • Control Tag (Visual Studio) ($P[COMPONENT_VISUAL_STUDIO_TAG]): the default Visual Studio tag of a control, which is the type name of the control. For example, "Button" for the System.Windows.Forms.Button control.
  • Type Tag ($P[TYPE_TAG]): the tag of the type defined in the Type Tags Options.
  • Type Tag With Upper Case ($P[TYPE_TAG_WITH_UPPER_CASE]): the tag of the type defined in the Type Tags Options in upper case (useful if your constants use upper case and include a type tag).
  • Type Name ($P[TYPE_NAME]): the name of the type. For example, "Car".
  • Type Name With Lower Initial Letter ($P[TYPE_NAME_WITH_LOWER_INITIAL]): the name of the type with lower initial letter. For example, "car".
  • Base Type Name ($P[BASE_TYPE_NAME]): the name of the base type.
  • Array Tag ($P[ARRAY_TAG]): the tag for arrays defined in the Type Tags Options.
  • Parent Code Element Name ($P[PARENT_CODE_ELEMENT_NAME]): the name of the parent code element. For example, the namespace name for a class.

The New Method / Property Assistant Options allows you to use the following predefined variables:

  • Property Name ($P[PROPERTY_NAME]): the name of the property.
  • Property Name With Lower Initial Letter ($P[PROPERTY_NAME_WITH_LOWER_INITIAL]): the name of the property. with lower initial letter. This is useful if you want to generate a field named "_age" for a property named "Age".
  • Method Name ($P[METHOD_NAME]): the name of the method.
  • Method Name With Lower Initial Letter ($P[METHOD_NAME_WITH_LOWER_INITIAL]): the name of the method. with lower initial letter. This is useful if you want to generate a result variable named "getBalanceResult" for a method named "GetBalance".

The Replace Text feature of MZ-Tools allows you to use the following predefined variables. This can be useful in composing the replacement text:

  • Found Text ($P[FOUND_TEXT]): the text that has been found according to the search criteria.
  • Found Line ($P[FOUND_LINE]): the whole line where the text has been found.
  • Portion of Line to the Left of Found Text ($P[LEFT_PORTION]): the text in the line before the found text.
  • Portion of Line to the Right of Found Text ($P[RIGHT_PORTION]): the text in the line after the found text.

Converting MZ-Tools 3.0 predefined variables

If the .ini options file of MZ-Tools 3.0 is present on the system when MZ-Tools 8.0 is loaded for the first time, you should get a prompt to import the options (code templates, headers, error handler, etc.), which also converts the predefined variables from the old version to the new one. If you need to convert them by hand, the equivalence is the following:

MZ-Tools 3.0 Predefined variable

MZ-Tools 8.0 predefined variable

{PROJECT_GROUP_FILENAME_WITH_PATH}

$P[PROJECT_GROUP_FILENAME_WITH_PATH]

{PROJECT_NAME}

$P[PROJECT_NAME]

{PROJECT_FILENAME}

$P[PROJECT_FILENAME]

{PROJECT_FILENAME_WITH_PATH}

$P[PROJECT_FILENAME_WITH_PATH]

{MODULE_NAME}

$P[PARENT_CODE_ELEMENT_NAME]

{MODULE_TYPE}

$P[PROJECT_ITEM_KIND]

{MODULE_FILENAME}

$P[PROJECT_ITEM_FILENAME]

{MODULE_FILENAME_WITH_PATH}

$P[PROJECT_ITEM_FILENAME_WITH_PATH]

{PROCEDURE_BODY}

$P[METHOD_BODY_EXCLUDING_DECLARATIONS]

{PROCEDURE_NAME}

$P[CODE_ELEMENT_NAME]

{PROCEDURE_NAME_CONTROL_NAME}

$P[CODE_ELEMENT_NAME]

{PROCEDURE_TYPE}

$P[CODE_ELEMENT_KIND_KEYWORD]

{FUNCTION_RETURN_TYPE_NAME}

$P[METHOD_RETURN_TYPE_NAME]

{FUNCTION_RETURN_TYPE_PREFIX}

$P[METHOD_RETURN_TYPE_PREFIX]

{AUTHOR}

$P[AUTHOR]

{DATE}

$P[DATE]

{TIME}

$P[TIME]

{I}

$P[I]

See Also:

User-defined variables