Class ModuleHeader
Reads what a VBA module's header says about the module itself, and writes the header of a new module.
public static class ModuleHeader
- Inheritance
-
ModuleHeader
- Inherited Members
Remarks
A class or designer module (a .cls, a UserForm) is exported with a VERSION
header line (VERSION 1.0 CLASS for a class, VERSION 5.00 for a designer) followed by
a BEGIN … END attribute block. A standard module has no such header and opens directly on
its Attribute VB_Name. The presence of the VERSION line is the signal, independent
of the file extension: RD-VBA determines a module's kind from its source, not from .cls vs
.bas.
A document module's export (a .doccls) carries no header: what makes a module one is the
project's word for it, which Of(DocClassType?, string?, string?) reads before this.
Methods
AttributesLineOf(string?)
The line of source a module's first attribute goes on, which is where an edit inserts its Attribute VB_Name
when its source writes none. A module's name is its VB_Name (MS-VBAL §4.2); a module whose source writes none is named
by its file.
public static int AttributesLineOf(string? source)
Parameters
sourcestringThe module file's text, or
nullwhen it could not be read.
Returns
- int
The zero-based line;
0for no text.
Remarks
The line follows the header: after the VERSION line, the Object lines of the controls the module uses, and the header's
Begin … End block, at the End of its own Begin (a designer's block holds its controls' blocks). A module
without a VERSION first line has no header: its attributes go on its first line. A block whose End the text never writes
ends with the text, and the attributes go on its last line. Lines are split as NameRangeOf(string?) splits them.
DesignerOf(string?)
The designer source's header names: the Begin <class> <name> line that opens a designer module's designer
block, which is what makes the module a form, an MDI form, a user control or a property page of Visual Basic 6.0 (VB.Form,
VB.MDIForm, VB.UserControl, VB.PropertyPage), or a VBA UserForm.
public static DesignerHeader? DesignerOf(string? source)
Parameters
sourcestringThe module file's text, or
nullwhen it could not be read.
Returns
- DesignerHeader
The designer, its class, the name it gives the form, where, and the line that closes its block (EndLine); or
nullwhen the text has no such header: a standard or class module, or no text.
Remarks
The header is a VERSION line (VERSION 5.00) on the text's first line that is not blank; then the Object lines of the ActiveX
controls a Visual Basic 6.0 designer uses, and blank lines; then the Begin line. A class module's header names no designer: its
VERSION 1.0 CLASS is followed by BEGIN alone. A Microsoft Forms class identifier names a UserForm, whose class is
MSForms.UserForm (MSFormsDesignerClassId); any other is the class identifier alone. Lines are split as
NameRangeOf(string?) splits them.
IsClassModule(string?)
Whether source carries a module VERSION header: it is a class
or designer module. null when there is no source to inspect.
public static bool? IsClassModule(string? source)
Parameters
sourcestringThe raw module source, or
nullwhen it could not be read.
Returns
- bool?
Remarks
The header is the file's own module's: a VERSION line inside a block of the file (FileBlocks) is the block's code.
NameAttribute(string, string)
A module's Attribute VB_Name line (MS-VBAL §4.2): the whole header of a new standard module's file, as the VBE exports
one, and the line an edit inserts at AttributesLineOf(string?) into a module of any kind that does not name itself.
public static string NameAttribute(string name, string newLine)
Parameters
namestringThe module's name; a quote in it is written doubled, as FromSource(string?) reads it.
newLinestringThe line break that ends the line: the text the line goes in uses one.
Returns
- string
The line, ended: the module's code or its next attribute follows it.
Exceptions
- ArgumentException
nameornewLineis empty.
NameRangeOf(string?)
Where the Attribute VB_Name line that names the module (FromSource(string?)) writes its name: the range between its quotes.
public static SourceRange? NameRangeOf(string? source)
Parameters
sourcestringThe module file's text, or
nullwhen it could not be read.
Returns
- SourceRange?
The name's range, which is empty for
Attribute VB_Name = ""; ornullwhen no line names the module, which is then named by its file.
Remarks
Lines are the text's as a client of the protocol counts them: a carriage return and a line feed, a line feed, and a carriage return each end one. The range is zero-based, on one line, and covers the name as written, a doubled quote included. A line that does not name the module is not it: a line inside a block of the file (FileBlocks), or one with more than the attribute on it, such as a comment.
OfClassModule(string, ClassInstancing, bool, string)
The header of a new class module's file, as the VBE exports one: the VERSION 1.0 CLASS block, then its attributes (MS-VBAL §4.2,
§5.2.4.1): VB_Name, VB_GlobalNameSpace = False, VB_Creatable and VB_Exposed for its
instancing, and VB_PredeclaredId.
public static string OfClassModule(string name, ClassInstancing instancing, bool predeclaredId, string newLine)
Parameters
namestringThe class's name; a quote in it is written doubled, as FromSource(string?) reads it.
instancingClassInstancingWhether projects that reference the class's project see it and create it.
predeclaredIdboolWhether the class has a default instance (MS-VBAL §5.2.4.1.2).
newLinestringThe line break that ends each line: the text the header goes in uses one.
Returns
- string
The header, its last line ended: the class's code follows it.
Exceptions
- ArgumentException
nameornewLineis empty.- ArgumentOutOfRangeException
instancingis not a ClassInstancing value.