Model to Visual Basic Mapping Overview

The notations provided by Visual Modeler are more abstract than the Visual Basic programming language. Some types of model elements in Visual Modeler do not have any correspondences in Visual Basic at all. But many of them result in several lines of Visual Basic code when generated.

Visual Modeler uses the specifications and model properties of the model elements to produce Visual Basic source code. For each model element in Visual Modeler there is a default mapping, but you can also control what code to generate by changing the model properties for the model element.

Click on an element type below to get an explanation of the meaning of it as well as the mapping to Visual Basic code:

Logical View

Classes

Interfaces

Class Utilities

Collection Classes

Packages

Properties

Relationships

Association Relationship

Navigability

Containment Adornment

Cardinality and Multiplicity

Aggregation Relationship

Generalization Relationship

Dependency Relationship

Methods

Parameter Passing

DLL Library Usage

Events

Property Get/Set/Let Procedures

Entry and Exit Code

Initialization and Termination Methods

Component View

Components

Interfaces


Classes and Visual Basic

A class is a set of objects that share a common structure (that is properties and relationships) as well as a common behavior (that is methods). A class is by default translated as a Visual Basic class module.

The stereotype of a class defines to what a class corresponds in the Visual Basic code. A class may correspond to a class module, module, form, MDI form, property page, user document, user control, etc.

A class may also represent a user-defined data type or an object type, for example ListBox or Database, in the Visual Basic environment. Such a class may have the stereotype ‘Data Type‘ or ‘Control‘. The code generator ignores those classes when generating class definitions in the source code.

Visual Basic supports public and private access control and visibility forms. Therefore, each property, relationship, and method in the class specification will be mapped appropriately to the public or private visibility tag from the class specification. Visual Basic methods with friend access control are mapped as protected visibility forms in Visual Modeler.

To generate Visual Basic code for a class, the class has to be assigned to a component with Visual Basic as the implementation language. A class can be assigned to and implemented by several Visual Basic components.

For each class, using the default mapping as a class module, the Visual Modeler produces the following code constructs:

•	Class annotations extracted from the class specification.

•	A class definition, taken from the name and properties of the class.

•	Module variables that are generated from the class properties, aggregation, and association relationships.

•	User-defined function procedure declarations that are defined in the class specification, and skeletal function procedure bodies.

•	User-defined property procedures and initial method bodies.

•	Initialization and termination methods, and skeletal function procedure bodies.

•	For each generated project item, member, and method, Visual Modeler adds an identifier as a code comment (for example “ModelID=3237F8CE0053”), which identifies the corresponding class, property, role, or method in the model.

 Example

Note:	Visual Modeler does not validate class names. That is, Visual Modeler does not check for invalid characters or length of class names. It is recommended that you only use class names that are accepted by Visual Basic.

See Also

Model Properties for Classes

Stereotypes of Classes


Example of Visual Basic Code Generated for a Class

The following example illustrates the Order class, a typical class from the Business Service layer, and the supporting Visual Basic class module definition:

Public Orderrows As Collection 'of OrderRow

Private pPurchaser As Customer

Private pOrder_Id As Variant

' Stores the order, initiates shipping and invoice.

Public Sub Register()

...

End Sub

' Calculates the total sum of the order.

Public Property Get Sum() As Currency

   Dim tempSum As Currency

   Dim thisOrderRow As OrderRow

   'Initilize the sum

   temp_sum = 0

   'Iterate over the order rows and calculate the sum

   For Each thisOrderRow In Orderrows

      tempSum = tempSum + thisOrderRow.Sum

   Next

   'Return the calculated sum

   Sum = tempSum

End Property

' Adds an order row to the order.

Public Sub Add_OrderRow() new_order_row As OrderRow

   Orderrows.Add new_order_row

End Sub

Public Property Get Purchaser() As Customer

   Set Purchaser = pPurchaser

End Property

Public Property Set Purchaser() Value As Customer

   Set pPurchaser = Value

End Property


Interfaces and Visual Basic

An interface specifies the externally visible methods of a class and/or component, and has no implementation of its own. In Visual Modeler, an interface is represented by a class with the stereotype “Interface”. When generating code for an interface, the code generator creates a class module with the instancing property Public.

Interfaces are used to represent the interface classes of components that are reverse engineered into the model. Interfaces belong to the logical view, but they are also displayed on component diagrams to represent the interface of the components.


Class Utilities and Visual Basic

A class utility denotes a set of services provided by a module in the system under construction. A class utility can therefore be used to collect a set of free methods and data types. For instance, consider a collection of subprograms from Window 3.1 kernel, GetProfileString and WriteProfileString for example, that manipulate the WIN.INI configuration file. These can be gathered together into a class utility.

A class utility is mapped as a module in Visual Basic. Its properties are mapped as public or private module variables, and the methods are mapped as public or private module methods.

For each class utility, Visual Modeler produces the following code constructs:

•	Class annotations extracted from the class specification.

•	Module variable declarations that are generated from the class properties and association relationships.

•	User-defined function procedure declarations that are defined in the class specification, and skeletal function procedure bodies.

 Example


Example of Visual Basic Code Generated for a Class Utility

The following example shows the mapping of utilities to Visual Basic code:

Const SWP_NOMOVE = 2

Const SWP_NOSIZE = 1

Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Const HWND_TOPMOST = -1

Const HWND_NOTOPMOST = -2

Declare Function GetProfileInt% Lib "Kernel" _
(ByVal lpAppName$, ByVal lpKeyName$, ByVal nDefault%)

Declare Function GetProfileString% Lib "Kernel" _

(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%)

Declare Function WriteProfileString% Lib "Kernel" _

(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpString$)

Declare Function GetPrivateProfileInt% Lib "Kernel" _

(ByVal lpAppName$, ByVal lpKeyName$, ByVal nDefault%, ByVal lpFileName$)

Declare Function GetPrivateProfileString% Lib "Kernel" _

(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, _

 ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)

Declare Function WritePrivateProfileString% Lib "Kernel" _

(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpString$, ByVal lpFileName$)

Declare Function SetWindowPos$ Lib "user"
(ByVal h%, ByVal hb%, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, ByVal f%)


Collection Classes and Visual Basic

Collections provide methods for adding objects to and removing objects from a collection. They also provide behavior for processing the entire collection, such as behavior for iterating the entire collection using the For Each...Next statement in Visual Basic.

A collection object is created in the same way as an ordinary object. For example:

Dim myDatabases As New Databases

Visual Basic provides a pre-defined standard collection object, Collection, which can be used to create simple collections. However, for collections with more complex behavior, the methods provided by the standard collection are not sufficient.  For example, an order administrator may need information on how many orders were received during a specified period. Then, it is natural to let a collection object, Orders, provide the behavior needed to collect that information.

Visual Modeler models are very well suited to document and illustrate the object hierarchy of Visual Basic applications. In a model, user-defined collections are represented by classes, and associations between collection classes and contained classes represent the containment relations:

To each class in the model, there is a collection class assigned—either a user-defined collection class or the standard collection (Collection). The name of the collection class that is assigned to a class is given by its CollectionClass model property. For example, the value of the CollectionClass property for the Order class above is “Orders”.

By default, Visual Modeler assigns the standard collection class, Collection, to new classes in the model. Note, however, that the standard collection is not explicitly represented in the model. Only user-defined collection classes are represented in the model.

 Example

See Also

Generating a new user-defined collection class during code generation

Assigning a new user-defined collection class to a class and generate it later

Assigning an existing collection class to a class


Example of Visual Basic Code Generated for a Collection Class

Because of the importance of containment hierarchies and collections in Visual Basic, Visual Modeler provides mechanisms to automatically generate user-defined collection classes. This example shows a class, Order, and a user-defined collection class, Orders, which has been automatically generated by Visual Modeler.

By default, there is a unidirectional association between the class and the automatically created collection class, with the multiplicity “0..*”.

When creating a collection class, Visual Modeler automatically creates the standard collection methods: add, item, remove, count, and enum. The following code is generated for the Orders collection class in this example:

Private mCol As Collection

Public Property Get Item(vntIndexKey As Variant) As Order

   Set Item = mCol(vntIndexKey)

End Property

Public Sub Remove(vntIndexKey As Variant)

   mCol.Remove vntIndexKey

End Sub

Public Sub Add(Item As Variant, Optional Key As String, Optional Before As Variant, Optional After As Variant)

    If IsMissing(Key) Then

        mCol.Add Item

    Else

        mCol.Add Item, Key

    End If

End Sub

Public Property Get Count() As Long

   Count = mCol.Count

End Property

Public Property Get NewEnum() As IUnknown

   Set NewEnum = mCol.[_NewEnum]

End Property

Private Sub Class_Initialize()

   Set mCol = New Collection

End Sub

Private Sub Class_Terminate()

   Set mCol = Nothing

End Sub


Logical Packages and Visual Basic

A logical package is a collection of classes that are strongly cohesive within the collection and loosely coupled to classes outside the collection. Each logical package represents a chunk of the logical architecture of the system.

Each package declares its dependencies to other packages using a dependency diagram as shown below. The dependency relationships indicate that the classes contained by the BO_ORDER package have visibility to the classes exported by the BO_CUSTOMER and BO_ARTICLE packages. All classes in the model have visibility to the classes exported by the RDO and VB packages, because these packages are declared as global. Violations to the visibility rules, that is the system architecture, are checked by Visual Modeler.

Logical packages have no direct mapping to Visual Basic code, but they are used to represent external software components in the model.

See Also

Model Properties for Packages


Properties and Visual Basic

A property (or attribute) is a data member of a programming-language type that is not a class. If a “property” is an object, it should be modeled as an association to the corresponding object class.

Class properties and relationships of a class module are translated into data members.

By default, Visual Modeler does not generate the property Get, Set and Let procedures corresponding to each property. A model property allows the user to turn on automatic generation of property procedures. The code generator will rename the generated property to avoid name collision between the data member and property procedure names.

For each generated member, Visual Modeler adds an identifier as a code annotation, to be able to identify the corresponding property in the model.

See Also

Property Get/Set/Let Procedures

Model Properties for Properties


Association Relationships and Visual Basic

An association is a bi-directional class relationship that denotes a semantic dependency between two classes. Associations map to pairs of data members in Visual Basic. The name for each data member is taken from its association role name.

Associations can be described in detail by assigning a variety of adornments and properties. These adornments include for example: association direction, roles, multiplicity, navigability, aggregate, access, containment, role documentation, etc.

For each generated member, Visual Modeler adds an identifier as a code annotation, which identifies the corresponding role in the model.

 Example of code generation for an association

 Example of code generation for an association with unbounded multiplicity

See Also

Navigability

Property Get/Set/Let Procedures

Model Properties for Association Roles


Example of Code Generated for an Association Relationship

The following example shows the mapping of associations into Visual Basic code. Code has been generated with the GenerateGetOperation and GenerateSetOperation model properties for the pOrders and pPurchaser roles.

ORDER.CLS class module.

…

Public Orderrows As Collection 'of OrderRow

Private pPurchaser As Customer

Private pOrder_Id As Variant

…

Public Property Get Purchaser() As Customer …

Public Property Set Purchaser( Value As Customer) …

…

CUSTOMER.CLS class module.

…

Private pOrders As Collection 'of Order

Private pCustomer_Id As Variant

Private pName As Variant

Private pAddress As Variant

Private Storage As Persistence

…

Public Property Get Orders _
(Index As Variant) As Customer …

Public Property Set Orders _
(Index As Variant, Value As Order


Example of Code Generated for an Association with Unbounded Multiplicity

An unbounded multiplicity of an association in the model indicates the need for a collection object. When generating code for an association role with unbounded multiplicity, such as the Orderrows role in the following picture, Visual Modeler automatically detects the need for a collection object, and uses the CollectionClass code generation option of the class Orderrow to generate the data member declaration.

Thus, Visual Modeler generates the following code by default for the Orderrows role into the class module of Order:

Public Orderrows As Collection

If there is a user-defined collection class to handle collections of Orderrow objects, as in the figure below, the name of that class is used in the declaration instead of the standard collection.

For example, for the Orderrows role above, the following declaration is generated into the class module of Order:

Public Orderrows As Orderrows


Aggregation Relationships and Visual Basic

An aggregate relationship is conceptually the same as an association with the aggregate adornment set. The aggregate association adornment denotes a whole or part relationship. Aggregate adornments are purely conceptual and have no effect on code generation, nor reverse engineering.

An aggregate relationship is by default navigable on one side, and a data member for the supplier class is generated into the client class.


Dependency Relationships and Visual Basic

The dependency relationship in the logical view denotes a client/supplier relationship in which the client object invokes a method on the supplier. Typically, this means that the client is dependent on the interface of the supplier, but does not contain an instance of the supplier.

Visual Basic does not support the visibility declaration. Thus, there are no mappings for dependency relationships in the logical view.


Generalization Relationships and Visual Basic

A generalization relationship exists when one class, called the superclass, shares its properties, methods, relationships, and constraints with another class, called the subclass, or when a class conforms to the interface of the superclass.

In Visual Basic, the closest correspondence to the generalization relationship is the implements construct. Thus, for a generalization relationship between a subclass B and a superclass A, Visual Modeler generates by default the following code into B’s class module:

•	An Implements A statement

•	An object of the superclass

•	Copies of A's public methods, including default dispatching implementations that delegate to the parent class A

•	Private Get, Set, and Let procedures for A’s public properties and roles

By setting the generalization model property ImplementsDelegation to False, you can exclude the superclass object and the dispatching implementations, which is to prefer if the superclass, A, is defined in a type library without code, or if B is supposed to provide its own implementation of the inherited methods.

Note that there is an important difference between inheritance and implements in Visual Basic: Inheritance is transitive. Thus, if B inherits from A, and C inherits from B, then C inherits from A. Implements is not transitive. Thus, if B implements A, and C implement B, then C does not implement A implicitly.

Note: Generalization relationships between class utilities do not result in any Visual Basic code.

  Example


Example of Visual Basic Code Generated for a Generalization Relationship

The following example shows the mapping of the generalization relationship into Visual Basic code (if the ImplementsDelegation model property on the generalization relationship is True):

CLASSA.CLS class module.

Public Sub PublicMethod()

End Sub

Private Sub PrivateMethod()

End Sub

CLASSB.CLS class module.

Implements A

Private mAObject As New A

Private Sub A_PublicMethod()

mAObject.PublicMethod

End Sub

CLASSC.CLS class module.

Implements B

Private mBObject As New B

Note: Implements means conformance only to parts of the public interface. For example, B inherits A’s public method and gets a private Sub A_PublicMethod(). C implements the public interface of B, but A_PublicMethod()is not public in B. Therefore, according to the Visual Basic programming language, there is no Sub B_A_PublicMethod in C.


Navigability and Visual Basic

A navigable association adornment indicates the implementation direction of an association. A data member is generated only on the navigable side of the association. By default, a new association relationship becomes navigable in both directions. To remove the navigability for one of the directions, point to that end of the association and press the right mouse button. Clear the Navigable option on the displayed menu. An arrow now shows in which direction the association is navigable.

  Example


Example of Visual Basic Code Generated for a Navigable Association

The following example shows the mapping of a navigable association into Visual Basic code.

CUSTOMER.CLS class module.

…

Public Orderrows As Collection 'of OrderRow

…


Containment Adornments and Visual Basic

By-Value and By-Reference containment adornments are not directly applicable to Visual Basic code generation, because all object references are implemented By-Reference.

Conceptually, the By-Value aggregate implies that the lifetime of the containing and contained objects are identical. As such, it is expected that the initialization method for the containing object will create its contained objects, and the termination method of the containing object will destroy the contained objects.

The By-Reference aggregate implies that the lifetime of the containing and contained objects are different. As such, it is expected that the initialization for the containing object will not create its contained By-Reference objects, and the termination method of the containing object will not destroy the objects. Object references are often passed by method or property procedure calls.


Cardinality/Multiplicity and Visual Basic

Relationship multiplicity indicates the number of links between each instance of the classes. The multiplicity on a relationship affects the code generated for the corresponding object. A multiplicity of 1 results in the simple data member of one object within another. A multiplicity larger than one is implemented using either an array object definition (for fixed multiplicities) or a collection object (for unbounded multiplicities). The Subscript model property can also be used for specifying the data member subscript.

When a class variable, module variable, or data type field is generated from an aggregation, ‘has’ or association relationship Visual Modeler looks at the supplier cardinality to determine what kind of data member to generate. (The client cardinality of the relationship is ignored.) In general, the cardinality of the supplier in the relationship determines the data member type:

•	A supplier cardinality of 0 forces Visual Modeler to ignore the relationship and no variable or field is generated.

•	A supplier cardinality of 0..1 or 1 generates a variable.

•	A supplier cardinality greater than 1 usually requires an array or a container class.

•	An unbounded cardinality, that is 0..n, 1..n, or n, is mapped using a container class. Visual Modeler generates, by default, a variable declaration using the Visual Basic collection class. The CollectionClass model property can be used to change the default class to a user-defined collection class.

•	A bounded cardinality is mapped as an array with a subscript. The Subscript model property can be used to specify a subscript using constants, for example “(1 To MaxLen)” or “(mnuOpen To mnu Quit)”. Dynamic arrays may be declared by setting the Subscript model property to “()”.


User-Defined Methods and Visual Basic

Visual Modeler allows you to specify several aspects of a method:

•	The method stereotype supports tagging a method as Common (that is Sub or Function), as a DLL method , event , or a property procedure. Property procedures must specify the property kind, that is Get, Set or Let. Initialization and termination handlers may be automatically generated for each class module.

•	Methods can be declared:

public - allowing use from other modules. Visual Modeler translates the method into a visible function or sub declaration.

private - allowing use only from within the module. Visual Modeler translates the method into a private function or sub declaration.

protected - allowing use only from within the project. Visual Modeler translates the method into a friend function or sub declaration.

•	Method names, in modules, can not be overloaded in Visual Basic. To simulate the class name scooping of method, Visual Modeler creates unique method names by prefixing the method name with the class name or by adding a unique number to the method name. This default behavior can be modified using the OperationName model property.

•	Method arguments are declared with a unique name and argument type. The type definition can be omitted, implying the use of a Variant data type. A function method is declared by specifying a return type in the method specification. A sub method is declared by leaving the return type field empty. The argument passing mechanism can be specified by appending a key word in front of the argument name.

•	Methods can be static, indicating that the Sub procedure's local variables are preserved between calls. Methods are marked as static by using the IsStatic model property.

•	In each generated method, Visual Modeler adds a unique identifier as a code comment.

•	Entry and exit code can be added to the methods.

  Example

See Also

Model Properties for Methods

Stereotypes of Methods


Example of Visual Basic Code Generated for a Method

For each method, Visual Modeler produces documentation and code according to the following rules:

' The Documentation field of the method specification is inserted here as a comment.

visibility method_type method_name(method_arguments)As return_type

' The first time a method is generated, the entry code, as specified by the method’s EntryCode model property, is inserted here as code. If the EntryCode is empty, but the Include Err.Raise in All Generated Procedures option in the Code Generation Wizard is selected, the following entry code is generated by default:

On Error GoTo AlfaMethodErr

' If the Include Comments option in the Code Generation Wizard is selected, the following comment is inserted here the first time a method is generated:

' your code goes here…

' The first time a method is generated, the exit code, as specified by the method’s ExitCode model property, is inserted here as code. If the ExitCode is empty, but the Include Err.Raise in All Generated Procedures option in the Code Generation Wizard is selected, the following exit code is generated by default:

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End method_type


Method Parameter Passing and Visual Basic

The Visual Basic programming language allows specification of the parameter passing mechanism as well as dynamic parameter cardinality. The passing mechanism for each parameter can be specified by appending a key word in front of the argument name.

If you enter:	The parameter is declared as:

ByVal argname	Passed by value

ByRef argname	Passed by reference

Optional argname	Optional parameter

ParamArray argname	Indefinite number of parameters

Note that you do not have to specify the passing mechanism in Visual Modeler. You can do it later, in Visual Basic, after you have generated the code. When you reverse engineer the code, the passing mechanism key word is automatically appended to the argument names.

You are also able to define default initial values of method arguments. These values are directly mapped to default parameter values in the Visual Basic code.

  Example


Example of Visual Basic Code Generated for Method Arguments

The following example shows the mapping of a method, X, with an optional argument Y of the type String with the initial value “Z”:

CLASSA.CLS class module.

Public Sub X(Optional Y As String = “Z”)

End Sub


Property Get/Set/Let Procedures in Visual Basic

Generation of property procedures can be specified in two different ways:

•	In the Code Generation Wizard (or via the PropertyGet/Set/LetOperation model properties), class properties and roles can be defined to generate both the variable declaration and associated property Get, Let, and/or Set procedures.

•	In the model, property procedures can be created directly by creating the method and giving it the stereotype Get, Set, or Let. The stereotype of a method can also be specified in the Code Generation Wizard by selecting the appropriate method kind.

The first approach is best for simple property procedure declarations where both the data member and its property procedure are intended. While the second approach is used when more complex parameter passing is used in the property procedure, or a specific property name is required.

Property procedures are also generated for all public roles and properties of a superclass, A, into the class modules of its subclasses. See Generalization Relationships and Visual Basic.

Note: There is no correspondence between properties and property procedures. Thus, if you change the name of a property and want its property procedures to get the new name, you have to manually change the property procedure names.


DLL Library Usage in Visual Basic

A method in a class or class utility can be declared as a reference to a DLL library procedure. Visual Modeler transforms the method into a Declare Sub or Declare Function statement.

To reference a method to a DLL procedure the method stereotype should be set to “Declare” .

The DLL library and method alias name are set using the LibraryName and AliasName model properties. These properties are available in the Code Generation Wizard.


Events in Visual Basic

A method in a class or class utility can be declared as an event, by setting the method stereotype to “Event”. Visual Modeler then transforms the method into an event declaration statement. This setting can be done in the Code Generation Wizard.


Entry and Exit Code in Visual Basic

Module methods often define exception handling in a macro-like way. The exception handler is declared in the first line of the method and the exception handler, including calls to an error or event handler, are added at the end of the method.

The EntryCode and ExitCode model properties are used to specify the entry and exit code for a method. The default value of these properties generates the following code if the Include Err.Raise in All Generated Procedures general option in the Code Generation Wizard is selected:

Public Function AlfaMethod() As Integer

On Error GoTo AlfaMethodErr

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End Function


Initialization and Termination Methods in Visual Basic

Visual Basic specifies two predefined methods for class instance creation and termination. The Initialize method is called when an object is constructed, while the Terminate method is called before the object is destructed.

You do not need to model these two methods. Visual Modeler can generate skeleton code for them (see Generate Initialization and Generate Termination model property). Also, when reverse engineering the code, Visual Modeler creates the initialization and termination methods in the model.


Components and Visual Basic

Components in the model are used to represent the software modules that together realize the modeled system. To generate Visual Basic code for a class, the class has to be assigned to one or several Visual Basic components. The programming language of a component is assigned in its specification, and the type of component (executable, data link library, etc.) is specified by its stereotype.

A component corresponds to a Visual Basic project. The physical instantiation of a component is the .exe, .dll, .tlb, or .ocx file that is produced from the corresponding project. The name and path of the component’s project file is stored in the ProjectFile model property of the component. A component can only be related to one project.

Components are also used to represent external software modules that the modeled system uses. Thus, ActiveX components can be dragged from the Microsoft Explorer or Microsoft Visual Component Manager and dropped in Visual Modeler. A component representing the external software module is then created in the model, and the interface of the component becomes one or several interface elements in the model.

By establishing relationships between classes and interfaces, and dependency relationships between components and interfaces, you can show how classes and components depend on the interfaces of other components.

A dependency relationship between a component and an ActiveX component in the model becomes a reference in the generated Visual Basic project.

See Also

Model Properties for Components

Stereotypes of Components


Visual Basic Model Properties Overview

The information contained in a model element's specification and model properties controls all aspects of code generation for that model element. The following Visual Basic model property groups exist:

Class Properties 	Role Properties

Property Properties 	Method Properties

Component Properties	Generalization Properties

Note: For model elements without a code mapping, such as packages, there are no model properties.


Model Properties for Components - VB

There is only one model property for components, which is:

ProjectFile

See Also

Components and Visual Basic


ProjectFile (Component Property) - VB

The ProjectFile property specifies the project file (.vbp) for the Visual Basic project where the component belongs. When generating code for a component, Visual Modeler generates the code into the project file specified by the ProjectFile property.

Visual Modeler sets this model property automatically when generating or reverse engineering code. You can view and change the value of the ProjectFile model property on the Visual Basic tab in the Component Specification dialog.

If you enter:	The action is:

“a file path”	(Default) Visual Modeler generates code into the specified project file.

Empty	Visual Modeler generates code into the current open Visual Basic project:

•	if the open project has the same name as the component or

•	if the component has been generated from/into that project before.

Otherwise, Visual Modeler starts the Visual Basic application and generates code into a new project.


Model Properties for Packages - VB

There are currently no model properties for logical packages because no code is generated for them.

See Also

Packages and Visual Basic


Model Properties for Classes - VB

Model properties for classes control the Visual Basic code that Visual Modeler produces for a class.

To learn more about a model property and its values, click on its name:

CollectionClass

Creatable

GenerateInitialization and GenerateTermination

OptionBase

OptionExplicit

OptionCompare

See Also

Classes and Visual Basic


CollectionClass (Class Property) - VB

The CollectionClass property specifies the container class that Visual Modeler uses when generating data members of a class with an unbounded cardinality. The default value of the CollectionClass property is "Collection".

The value of the CollectionClass model property can be changed on the Visual Basic tab in the Class Specification dialog box, and in the Code Generation Wizard.

If you enter:	The action is:

literal	Visual Modeler uses the named container object when generating data members.

“Collection”	(Default) Visual Modeler uses the Collection class when generating data members.


Creatable (Class Property) - VB

The Creatable property is used to determine how classes you define are exposed to other applications. It specifies, for example, whether or not you can create instances of a public class outside a Visual Basic project. The Creatable property is only relevant for classes with the stereotype set to “Class Module”.

For detailed explanations of the meaning of each value, please refer to the Visual Basic documentation.

The value of the Creatable model property can be changed on the Visual Basic tab in the Class Specification dialog box and in the Code Generation Wizard.

If you enter:	The action is:

Private	(Default) Visual Modeler makes the class visible only within a Visual Basic project.

PublicNotCreatable	Visual Modeler makes the class visible to applications outside the project, but instantiable only inside the project.

GlobalSingleUse	Please refer to your Microsoft Visual Basic documentation.

GlobalMultiUse	Please refer to your Microsoft Visual Basic documentation.

MultiUse	Please refer to your Microsoft Visual Basic documentation.

SingleUse	Please refer to your Microsoft Visual Basic documentation.


GenerateInitialization and GenerateTermination (Class Property) - VB

The GenerateInitialization and GenerateTermination properties are used to specify whether Visual Modeler creates skeleton code for the generated project item’s private Initialize and Termination procedures.

The value of the GenerateInitialization and GenerateTermination model property can be changed on the Visual Basic tab in the Class Specification dialog box.

If you enter:	The action is:

True	Visual Modeler creates the ItemType_Initialize and ItemType_Terminate procedure. For example:

Class_Initialize

Form_Initialize

False	(Default) Visual Modeler ignores the ItemType_Initialize or ItemType_Terminate procedure.


OptionBase (Class Property) - VB

The Option Base statement declares the default lower bound for array subscripts and is used to override the default base array subscript value of 0. The value of number must be either 0 or 1. The Option Base statement has no effect on arrays within user-defined types.

Visual Modeler inserts an Option Base statement in the Declarations section, before any array dimension declaration.

The value of the OptionBase model property can be changed on the Visual Basic tab in the Class Specification dialog box.

If you enter:	The action is:

“0”	(Default) Visual Modeler produces an Option Base 0 statement for the class module.

“1”	Visual Modeler produces an Option Base 1 statement for the class module.

Any other value	Visual Modeler does not generate an Option Base statement for the class module.


OptionCompare (Class Property) - VB

The Option Compare statement is used to declare the default comparison method to use when string data is compared.

The value of the OptionCompare model property can only be changed on the Visual Basic tab in the Class Specification dialog box.

If you enter:	The action is:

None	(Default) Visual Modeler does not produce an Option Compare statement for the module.

Text	Visual Modeler produces an Option Compare Text statement for the module.

Binary	Visual Modeler produces an Option Compare Binary statement for the module.

Database	Visual Modeler produces an Option Compare Database statement for the module.


OptionExplicit (Class Property) - VB

The Option Explicit statement is used in Visual Basic to force explicit declaration of all variables in that module. If you attempt to use an undeclared variable name, an error occurs at Visual Basic compile time.

Visual Modeler inserts an Option Explicit statement in the Declarations section.

The value of the OptionExplicit model property can be changed on the Visual Basic tab in the Class Specification dialog box.

If you enter:	The action is:

True	(Default) Visual Modeler produces an Option Explicit statement for the module.

False	Visual Modeler ignores an Option Explicit statement for the module.


Model Properties for Class Properties - VB

When generating code for a class, Visual Modeler produces a data member for each class property. A common practice in Visual Basic is to make data members private and to provide Get, Set, and Let member functions to read and modify member data. By default, Visual Modeler produces a basic implementation for Get and Set property procedures.

You use the following model properties to control the code generated for data members and their corresponding Get, Set, and Let property procedures. To learn more about a model property and its values, click on its name:

To control code for:	Use these properties:

Data members	GenerateDataMember
DataMemberName
NameIfUnlabeled
Subscript
New
WithEvents
IsConst

Property procedures	GenerateGetOperation
GenerateLetOperation
GenerateSetOperation

If the code generator discovers conflicts between the IsConst, WithEvents, New, and Subscript model properties, the following priority rules are used when generating code for a property:

Priority 1 - IsConst

Priority 2 - WithEvents

Priority 3 - New and Subscript

This means, for example, that if both IsConst and New are set to True, the property is generated as a constant, and the value of the New model property is ignored.

See Also

Properties and Visual Basic


Model Properties for Roles - VB

When generating code for a class, Visual Modeler produces a data member for each role. A common practice in Visual Basic is to make data members private and to provide Get and Set property procedures to read and modify member data. By default, Visual Modeler produces a basic implementation for Get and Set property procedures.

Use the following model properties to control the code generated for data members and their corresponding Get, Set, and Let property procedures. To learn more about a model property and its values, click on its name:

To control code for:	Use these properties:

Data members	NameIfUnlabeled
GenerateDataMember
DataMemberName
Subscript
New
WithEvents

Property procedures	GenerateGetOperation
GenerateLetOperation
GenerateSetOperation

If the code generator discovers conflicts between the WithEvents, New, and Subscript model properties, the following priority rules are used when generating code for a property:

Priority 1 - WithEvents

Priority 2 - New and Subscript.

This means, for example, that if both WithEvents and New is set to True, the property is generated with a WithEvents declaration, and the value of the New model property is ignored.


DataMemberName (Property or Role Property) - VB

The DataMemberName property specifies the name Visual Modeler produces for a data type field or module variable for a property or role when generating code.

Default value

The default value of the DataMemberName property is:

“$relationship”

When Visual Modeler produces a data member, "$relationship" expands to the label of the relationship in the model.

If the relationship is unlabeled, "$relationship" expands to the value of the NameIfUnlabeled property.

Changing the default value

The value of the DataMemberName model property can be changed on the Visual Basic tab in the Specification dialog boxes.

You can change the form of the names Visual Modeler uses for labeled relationships by changing the format of the DataMemberName property.

You can use the following variables when defining the value of the DataMemberName property:

•	$class

•	$package

•	$relationship

•	$supplier


GenerateDataMember (Property or Role Property) - VB

The GenerateDataMember property specifies whether or not Visual Modeler produces a data member corresponding to a property or role when generating code. The name of the data member is determined by the value of the DataMemberName property. The data member type is the supplier class.

You set the GenerateDataMember property to False if you want to provide your own data member definition or if you want to implement the property or role in some other way. After generating the code, you edit the generated file and add your own data member definition (or some other implementation of the property or role).

The value of the GenerateDataMember model property can be changed on the Visual Basic tab in the Specification dialog boxes.

If you enter:	The action is:

True	(Default) Visual Modeler produces a data member for the property or role.

False	Visual Modeler does not generate a data member for the property or role.


GenerateGet/Set/LetOperation (Property or Role Property) - VB

The GenerateGetOperation, GenerateSetOperation and GenerateLetOperation model properties specify whether or not Visual Modeler produces Get, Set and Let property procedures for the data member corresponding to a property or role.

You set the property to False if you want to provide your own property procedure definition, as the method definition, or if you want to implement the property procedure in some other way.

If the value is set to True, Visual Modeler creates an initial implementation for the generated property procedure. The generated property procedure simply copies the passed parameter to the data member, or returns the value of the data member. After generating the code, you can edit the generated property procedures in Visual Basic to add your own implementation. The value of the GenerateGet/Set/LetOperation property for the property or role is then changed to False.

The value of the GenerateGet/Set/LetOperation model property can be changed on the Visual Basic tab in the Specification dialog boxes and in the Code Generation Wizard.

If you enter:	The action is:

True	Visual Modeler generates a property procedure, together with an initial implementation, for the property or role. The value is then automatically changed to False.

False	(Default) Visual Modeler does not generate a property procedure for the property or role.

Naming principles

The property Get, Set and Let procedures are named using the property or role name, or the NameIfUnlabeled model property if the class property or role is unnamed. The data member is named using the DataMemberName model property.

To avoid name clashes between the data member and the property procedure names, the code generator uses the "m$supplier" naming standard for the DataMemberName model property.

Using this standard the data member and the property Get procedure for the "TheB" role is generated as shown below:

Private mTheB As B

Public Property Get TheB () As B

Note: The values of the GenerateGet/Set/LetOperation model properties have no effect on the code generated for generalization relationships. For each public role and property of a super class, A, the Visual Basic code generator always generates a property Get, Set, and Let procedure into all class modules that implements A (even if GenerateGet/Set/LetOperation=False for all roles and properties in A).


IsConst (Property Property) - VB

The IsConst property is used to specify whether Visual Modeler creates a constant declaration for a property. This model property is only relevant for properties with an initial value assigned.

The value of the IsConst model property can be changed on the Visual Basic tab in the Property Specification dialog box, and in the Code Generation Wizard.

If you enter:	The action is:

True	Visual Modeler creates a constant data member declaration.

False	(Default) Visual Modeler creates a data member declaration.

See Also

Model properties for class properties


NameIfUnlabeled (Property or Role Property) - VB

The NameIfUnlabeled property specifies the name to be used for an unlabeled property or role. Visual Modeler uses the property or role name to construct names for the corresponding data type field or module variable.

Default value

The default value of the NameIfUnlabeled property is:

“the$supplier”

When Visual Modeler needs the name of the property or role to generate a name for a data type field or module variable, "$supplier" expands to the name of the supplier class in the property or role.

For example, for an association between class A to class B, where B’s role is unlabeled, Visual Modeler uses "theB" as the name of the role when generating code.

Changing the default value

The value of the NameIfUnlabeled model property can be changed on the Visual Basic tab in the Specification dialog boxes.

You can change the form of the names Visual Modeler uses for unlabeled properties or roles by changing the format of the NameIfUnlabeled property. For example, if you set the NameIfUnlabeled property for a role to:

“$supplierrel”

Visual Modeler uses "Brel" as the name of the unlabeled role when generating code.

You can use the following variables when defining the value of the NameIfUnlabeled property:

•	$class

•	$package

•	$relationship

•	$supplier


New (Property or Role Property) - VB

The New property is used to specify whether Visual Modeler adds the ‘new’ keyword to the module variable declaration.

The value of the New model property can be changed on the Visual Basic tab in the Specification dialog boxes, and in the Code Generation Wizard.

If you enter:	The action is:

True	Visual Modeler adds the ‘new’ keyword to the module variable declaration.

False	(Default) Visual Modeler creates module variable declaration without implicit object allocation.

See Also

Model properties for class properties

Model properties for roles


Subscript (Property and Role Property) - VB

The Subscript property specifies the array subscript that Visual Modeler uses when generating data members for the selected property or role.

The subscript must include the subscript parenthesis, for example "(1 To MaxLen)" or "(mnuOpen to mnuQuit)".  The default value of the Subscript property is (blank).

The value of the Subscript model property can be changed on the Visual Basic tab in the Specification dialog boxes, and in the Code Generation Wizard.

If you enter:	The action is:

(blank)	(Default) No subscript is used when generating the data member.

“(literal)”	Visual Modeler uses the given array subscript when generating the data member.

“()”	Visual Modeler produces a dynamic array.

See Also

Model properties for class properties

Model properties for roles


WithEvents (Property or Role Property) - VB

The WithEvents property is used to enable events triggering from OLE Automation objects.

The value of the WithEvents model property can be changed on the Visual Basic tab in the Specification dialog boxes and in the Code Generation Wizard.

If you enter:	The action is:

True	Visual Modeler adds the ‘WithEvents’ keyword to the module variable declaration.

False	(Default) Visual Modeler creates module variable declaration without enabling event triggering.

See Also

Model properties for class properties

Model properties for roles


Model Properties for User-Defined Methods - VB

When generating code for a class, Visual Modeler produces a skeletal member function for each user-defined method that is detailed in the class specification. You use the following model properties to specify additional details that Visual Modeler uses when generating the member functions. To learn more about a model property and its values, click on its name:

AliasName

EntryCode

ExitCode

IsStatic

LibraryName

OperationName

See Also

User Defined Methods and Visual Basic


AliasName (Method Property) - VB

The AliasName property indicates that the procedure being called has another name in the DLL. This is useful when the external procedure name is the same as a Visual Basic reserved word. You can also use Alias when a DLL procedure has the same name as a Global variable, or constant, or any other procedure in the same scope. Alias is also useful if any characters in the DLL procedure name aren't allowed in Visual Basic names.

The AliasName property must be a string literal defining a valid alias name of the declared procedure.

The value of the AliasName model property can be changed on the Visual Basic tab in the Method  Specification dialog box, and in the Code Generation Wizard.


EntryCode (Method Property) - VB

The EntryCode model property is a text property that specifies additional code or comments for a user-defined method. You use the EntryCode property to specify code that you want to insert in a number of methods, such as instrumentation code.

Visual Modeler inserts the contents of the EntryCode property in the method body the first time the method is generated. Note that Visual Modeler does not check the correctness of the code you specify in the EntryCode property.

The EntryCode is only inserted the first time a method is generated.

Default value

By default, the EntryCode property contains exception handling. Visual Modeler generates the following entry and exit code if the Include Err.Raise in All Generated Procedures general option in the Code Generation Wizard is selected:

Public Function AlfaMethod() As Integer

On Error GoTo AlfaMethodErr

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End Function

Changing the value

The value of the EntryCode model property can be changed on the Visual Basic tab in the Method Specification dialog box; to generate other entry code than the code generated by default.

This is an example of entry code:

'## entry code (generated)

   on error goto main__exception

You can use the following variables when defining the value of the ExitCode property:

•	$class

•	$package

•	$operation

•	$type

See Also

Generating error handling code


ExitCode (Method Property) - VB

The ExitCode model property is a text property that specifies additional code or comments for a user-defined method. You use the ExitCode property to specify code that you want to insert in a number of methods, such as instrumentation code.

Visual Modeler inserts the contents of the ExitCode property in the method body the first time the method is generated. Note that Visual Modeler does not check the correctness of the code you specify in the ExitCode property. You must ensure that the flow of control passes through the exit code when appropriate.

Default value

By default, the ExitCode property contains exception handling. Visual Modeler generates the following entry and exit code if the Include Err.Raise in All Generated Procedures general option in the Code Generation Wizard is selected:

Public Function AlfaMethod() As Integer

On Error GoTo AlfaMethodErr

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End Function

Changing the value

The value of the ExitCode model property can be changed on the Visual Basic tab in the Method Specification dialog box; to generate other exit code than the code generated by default.

This is an example of exit code:

'## exit code (generated)

   exit Submain__exception:

   resume main__endmain__end:   exit Sub

You can use the following variables when defining the value of the ExitCode property:

•	$class

•	$package

•	$operation

•	$type

See Also

Generating error handling code


IsStatic (Method Property) - VB

The IsStatic property specifies whether or not Visual Modeler produces the function procedure for a user-defined method with the static keyword. This indicates that the function procedure's local variables are preserved between calls. The IsStatic property doesn't affect variables that are declared outside the function procedure, even if they are used in the procedure.

The value of the IsStatic model property can be changed on the Visual Basic tab in the Method Specification dialog box, and in the Code Generation Wizard.

The following table summarizes the possible values for the IsStatic property. In this table, result is the return type of the member function, fname is the name of the member function, and params is the formal parameter list:

If you enter:	The action is:

True	Visual Modeler produces a static Function procedure declaration. For example:

Static Sub fname (params)

Static Function fname (params) As result

False	(Default) Visual Modeler produces a Function procedure declaration. For example:

Sub fname (params)

Function fname (params) As result


LibraryName (Method Property) - VB

The LibraryName property specifies the name of the DLL that contains the declared method.

The value of the LibraryName model property must be a string literal. It can be changed on the Visual Basic tab in the Method Specification dialog box, and in the Code Generation Wizard.


OperationName (Method Property) - VB

The OperationName property specifies the name generated for a user-defined method. Visual Modeler uses the method name to construct names for the corresponding Function procedures.

Default value

The default value of the OperationName property is:

“$operation”

where “$operation” stands for the name of the method.

The name of a Function procedure can be made unique by prefixing the method name with the class name. Using this schema, several classes can declare overloaded method names.

Changing the value

The value of the OperationName model property can be changed on the Visual Basic tab in the Method Specification dialog box.

You can change the form of the names that Visual Modeler uses when generating Function procedures, by changing the format of the OperationName property. You can use the following variables when defining the value of the OperationName property:

•	$class

•	$operation

•	$package

For example, unique method names are created when the OperationName property is set to:

“$class$operation”

When Visual Modeler generates a name for a Function procedure, "$class" and "$operation" expands to the name of the class and the name or the method. For example, for a method called Add of a class called Order, the name of the generated Function procedure in Visual Basic becomes OrderAdd. Note that the name of the method is changed to OrderAdd also in the model.


Model Properties for Generalization Relationship - VB

There is only one model property for generalization relationships, which is:

ImplementsDelegation

See Also

Generalization Relationships and Visual Basic


ImplementsDelegation (Generalization Property) - VB

The ImplementsDelegation model property is used to control whether or not to generate code that delegates the implementation of the inherited public methods to the superclass. The default value of this model property is True. If the superclass is defined in a type library without code, or if the subclass is supposed to provide its own implementation of the inherited methods, you should use the value False.

The value of the ImplementsDelegation property can be changed on the Visual Basic tab in the Generalization Specification dialog boxes.

If you enter:	The action is:

True	(Default) Visual Modeler generates an object declaration and dispatching declarations of the superclass into the subclass. For example, if B inherits from A, which has a public method called methodA(), the following code is generated into B:

Implements A

Private mAObject As New A

Private Sub A_MethodA()

mAObject.MethodA

End Sub

False	Visual Modeler does not generate an object declaration and dispatching declarations of the superclass into the subclass. For example, if B inherits from A, which has a public method called methodA(), the following code is generated into B:

Implements A

Private Sub A_MethodA()

End Sub


Round-Trip Engineering Overview - VB

Visual Modeler provides support for controlled iterative development of your applications through the use of round-trip engineering. It allows you to make a quick model of an application under development, analyze it, and then refine it based on your ever-increasing understanding of the problem. You reiterate this process of modeling, analyzing, and refining until you are satisfied with the completeness and correctness of your model.

The round-trip engineering tools in Visual Modeler, which keep the model and the project consistent with each other, are tightly integrated with the Microsoft Visual Basic environment. Visual Modeler provides you with the following tools that support this method of development:

•	The code generator, which generates and updates the Visual Basic source code from the information contained in a model.

•	The reverse engineering tool, which extracts design information from the Visual Basic code and generates or updates a model representing the system’s design.

The overall process is illustrated below:

Round-trip engineering is the process by which each iteration of your application begins with the use of Visual Modeler to assess the current model, capture new scenarios, and extend the design to achieve specific objectives. From this model, Visual Modeler generates source code, preserving existing user-supplied definitions and declarations from the previous iteration's source code.

The generated code is then evolved using Visual Basic until the required functionality is achieved. In order to complete the code cycle, Visual Modeler is used to reverse engineer the extended implementation, producing an updated version of the model.

See Also

Round-Trip Engineering Process - Starting with a Model

Round-Trip Engineering Process - Starting with a Visual Basic Project


Code Generation Overview - VB

Using the Visual Basic code generator, you can produce Visual Basic source code from the information contained in a model. In addition to its support for round-trip engineering, the Visual Modeler code generator:

•	Substantially reduces the elapsed time between design and execution.

•	Produces uniform-structured source code, promoting consistent coding and commenting styles with minimal typing.

•	Synchronizes the code with the model.

Code generation is performed between the selected classes, or all classes assigned to the selected components, in an open model and the corresponding Visual Basic project. A component corresponds to one Visual Basic project. The name of the project file is stored as a model property of the component. The type of component is specified by the component’s stereotype. The first time you generate code for a specific component, Visual Modeler creates a new project of the chosen type.

The Effects of Code Generation

The code generated for each selected model element is determined by that element’s specification and model properties.

For each class in a component, Visual Modeler produces a corresponding Visual Basic project item. Class relationships and properties are translated to class variables, constants, class properties, module variables or data type fields, depending on the required implementation strategy. The code generator produces function procedures, or property procedures for the class methods. For all user-defined methods, the code generator produces skeletal function procedures that you must edit to add the function procedure bodies.

If classes, properties, roles, and methods have been renamed and/or removed from the model, Visual Modeler renames and removes the corresponding code elements during code generation. However, Visual Modeler lets you confirm each deletion.

Generated Additional Information

A model contains information that cannot be expressed in Visual Basic. However, all information that logically belongs with the generated source code is placed there as comments. The documentation field in a method specification, for example, is inserted as a comment preceding the declaration of the member function. Also, unique model element identifiers are placed as comments in the generated source code to support round-trip engineering.

See Also

Generating a New Visual Basic Project from a Model

Updating a Visual Basic Project from Changes in a Model

Visual Basic Model Properties

Model to Visual Basic Mapping


Reverse Engineering Overview - VB

Visual Basic reverse engineering is the process of examining a Visual Basic project to recover information about its design. Visual Modeler extracts design information and uses it to generate or update a model representing the application's logical structure. Visual Modeler enables you to view and manipulate this model using the UML notation for object-oriented analysis and design.

Use reverse engineering when:

•	Creating a new model from a project.

•	Updating an existing model with changes made to the code.

•	Adding Visual Basic components to your model.

A Visual Basic project corresponds to a component in the component view of a model. Reverse engineering is performed between the open project (if only one project is open), or a chosen project (if none or several projects are open), and the corresponding model. The name of the corresponding model file is stored as a related document to the project.

If classes modules, members, and/or methods have been renamed and/or removed from the project, Visual Modeler renames and removes the corresponding model elements during reverse engineering. However, Visual Modeler lets you confirm each deletion.

See Also

Visual Basic to Model Mapping


Visual Basic Model Properties Overview

The notations supported by Visual Modeler are more abstract than the Visual Basic programming language. Model properties enable you to provide language-specific information that is not expressed in the Visual Modeler notation, but that is necessary for generating Visual Basic code.

When a model element is created, Visual Modeler assigns each property a default value, which you can optionally modify. By modifying the model properties, you can control the kinds of Visual Basic code constructs that are generated for the model element.

The Code Generation Wizard lets you modify the most common and important model properties. Also, the Visual Basic model properties of a model element are available on the Visual Basic tab of its specification dialog box.

See Also

Visual Basic Model Properties Overview.

For general information about model properties and how to modify them outside the Code Generation Wizard, please refer to the Index or Contents tab of the on-line help.


Property Procedures - VB

Member functions that the Visual Modeler code generator can produce by default to provide safe access to class data members. You should augment these functions to include logic that preserves the validity of the class data member.


$class Variable - VB

The $class variable expands to the name of a class.

You can embed this variable in the values of the following model properties: NameIfUnlabeled, DataMemberName, OperationName, EntryCode, and ExitCode. When Visual Modeler puts the value of such a property into the generated code, it replaces $class with the name of the class. For example, unique method names can be created by setting the OperationName property to “$class$operation”. For a method called Add in class Order, the name of the generated method becomes OrderAdd in the code.


$package Variable - VB

The $package variable expands to the name of a package.

You can embed this variable in the values of the following model properties: NameIfUnlabeled, DataMemberName, OperationName, EntryCode, and ExitCode. When Visual Modeler puts the value of such a property into the generated code, it replaces $package with the name of the enclosing package.


$type Variable - VB

The $type variable expands to the type of method (Sub, Function, or Property).

You can, for example, embed this variable in the values of the EntryCode and ExitCode model properties. When Visual Modeler puts the value of such a property into the generated code, it replaces $type with the type of the class. For example, for a method of the type Sub, the string “exit $type” in the ExitCode the model property becomes “exit Sub“ in the code.


$relationship Variable - VB

The $relationship variable expands to the name of a relationship.

You can embed this variable in the values of model properties that specify the names of generated data members and property Get and Set procedures for a relationship. When Visual Modeler puts the value of such a property into the generated code, it replaces $relationship with the name of the relationship. (If the relationship is unlabeled in the model, $relationship expands to the value of the NameIfUnlabeled property.)


$operation Variable - VB

The $operation variable expands to the name of a method.

You can embed this variable in the values of model properties that control code generation of methods. For example, unique method names can be created by setting the OperationName property to “$class$operation”. For a method called Add in class Order, the name of the generated method becomes OrderAdd in the code.


$supplier Variable - VB

The $supplier variable expands to the name of the supplier class in an association relationship.

You can embed this variable in the values of model properties that control code generation for association relationships, roles and has relationships. When Visual Modeler puts the value of such a property into the generated code, it replaces $supplier with the name of the supplier class in the relationship. For example, if you set the NameIfUnlabeled model property for an unlabeled role on class B to “$supplierrel”, Visual Modeler uses "Brel" as the name of the unlabeled role when generating code.


Fundamental Data Type - VB

Fundamental types and standard objects built into the Visual Basic environment (Variant, String, and Collection etc.) are automatically included when a new model is created.


Project - VB

A Visual Basic project is a specially formatted file (.vbp) that identifies the folders and files containing your application's source code.

A Visual Basic project corresponds to a component in the component view of a Visual Modeler model. The physical instantiation of a component is the .exe, .dll, .tlb, or .ocx file that is produced from the project.

Code generation is performed between the selected classes, or all classes of the selected components, in an open model and the corresponding Visual Basic project. The name of the project file that corresponds to a component is stored as a model property of the component. A component can only correspond to one project.

Reverse engineering, from Visual Modeler, is performed between the open project (if only one project is open), or a chosen project (if none or several projects are open), and the corresponding model. The name of the corresponding model file is stored as a related document to the project. A project can have several related models.


Project Item - VB

A project item is an item that occurs in a Visual Basic project, such as a class module, form, user control, etc.


Related Document - VB

A related document is an external file that is attached to a Visual Basic project. The documents related to an open Visual Basic project are listed in a folder called Related Documents. When Visual Modeler generates code from a model into a Visual Basic project or reverse engineers a project into a model, the name and path of the model is added as a related document to the project.


Editing Diagrams and VB Classes - FAQ

I can’t paste classes into my diagram. Why?

You cannot use the Paste command to insert classes into three-tiered diagrams. The reason is that it is not clear into which of the tier the class should be inserted. You cannot use the Paste command in a Package Overview diagram for a package either, because that diagram can, by definition, only contain classes that belong to the package. The Paste command would therefore relocate the pasted class from the package where it was copied to the package that owns the Package Overview. Since that might not be what you wanted to do, the command is not available in those diagrams.

How do I name my classes, properties, and methods?

Visual Modeler does not validate names. That is, Visual Modeler does not check for invalid characters or length of names. Also, Visual Modeler is case sensitive, whereas Visual Basic regards, for example, a class module named “OrderRow” or “orderrow” as one and the same. Therefore, it is recommended that you only use names that are accepted and recommended by the Visual Basic programming language.


Generating Visual Basic Code - FAQ

How do I control and preview what code to generate for a class?

The code generator uses the model properties defined for each class, property, association role, and method to make the mapping of model elements to Visual Basic code. In the Code Generation Wizard you are able to define this mapping. That is, the Wizard allows you to change the model properties values for the selected classes and their properties, roles, and methods. It also gives you a preview of the code that will be generated with the current model property setting.

To simplify, the Code Generation Wizard lets you define the most common and important model properties. However, the model properties for a class, property, association, or method are available on the Visual Basic tab in its specification dialog. You can view and change all of the model property values in this dialog. By default, a predefined set of model properties is attached to each new model element. You can change that to another set on the Visual Basic tab. Also, the stereotype of a model element is used to specify the kind of project item to generate from it. The stereotype can be changed on the General tab of the model element’s specification.

How is inheritance (Generalization Relationship) in Visual Modeler mapped to Visual Basic code?

Inheritance means that one class shares its properties, methods, and relationships with another class or conforms to the interface of another class. In Visual Basic, the closest correspondence to the generalization relationship is the implements construct. Thus, for a generalization relationship between a subclass B and a superclass A, Visual Modeler generates by default the following code into B’s class module:

•	An Implements A statement

•	An object of the superclass

•	Copies of A's public methods, including default dispatching implementations that delegate to the parent class A

•	Private Get, Set, and Let procedures for A’s public properties and roles

Note that implements means only conformance to the public interface. Thus, B inherits only A’s public methods, not the private methods. Also, if a class C implements B, C does not implicitly implement A, because the implementation of A’s public methods in B becomes private in B. Also note that inheritance between class utilities in Visual Modeler do not result in any Visual Basic code.

I have generated code with the GenerateGet, GenerateSet, or GenerateLet model properties selected for some roles. Why are they deselected after the code generation?

They are deselected because the Code Generation Wizard creates the Property Get procedure both in the code and in the model. When the procedure is created the corresponding GenerateGet model property is reset.

How do I change the kind of Visual Basic project item to generate for a class?

Once you have generated a class, and started to evolve the generated code, you cannot alter its stereotype in Visual Modeler. If you do that, and then generate code from the class, the code generator replaces the existing project item with an item of the new kind, and you will lose the changes you have made to the source code. To change, for example, a class module into a form, create the form in the Visual Basic project, copy the code from the original class module, and then delete the class module.

I canceled the Code Generation Wizard before generating any code, but the settings I made during the preview of a class remain. Why?

The settings in the preview of a class are confirmed and stored after you’ve clicked Finish. To cancel the settings in a preview you have to click Cancel before finishing the preview.

I have generated code, but I’m not completely satisfied with the result. Which is the best way to proceed?

You can adjust the result in any of the two tools. Use the tool that best supports the changes you want to do. For example, minor changes, are best done directly in the code and then reverse engineered into the model. To adjust major problems delete the code changes by reopening the Visual Basic project, modify the model, and generate the code again.

I moved or copied a method from one class to another in the model and generated code. Why is the new method body in the Visual Basic project empty?

When you move or copy a method from one class to another, Visual Modeler regards the method as a new method in the other class. When generating code for a new method, the method body always becomes empty. Thus, if you have to move a method from one class to another, do it in the Visual Basic project and not in the model.

I have generated debug code for some classes. How do I remove the generated code?

The Include Debug Code option in the Code Generation Wizard applies only to classes that are generated for the first time. Remove the generated debug code in the Visual Basic project and reverse engineer the changes into the model.


Reverse Engineering Visual Basic Code - FAQ

How do I add existing software components to my model?

By reverse engineering existing software components into your model you can access and reuse their interface classes from other classes in your model. There are several ways to insert a component into the model:

•	There is a specific command for quickly importing the VB6 classes (without methods and properties). The command is called Import VB6 Classes, and is located on the Visual Basic submenu on the Tools menu.

•	To reverse engineer a Visual Basic component that is used by the application, choose Visual Basic from the Tools menu in Visual Modeler, and click Reverse Engineering Wizard. Select the ActiveX components you want to insert into your model. The created interface classes will be defined with Visual Basic data types.

•	To reverse engineer any software component (.exe, .dll, .ocx, .tlb file) into the model, drag the file from the Windows Explorer, or from the Microsoft Visual Component Manager, and drop it in the component view in Visual Modeler. The created interface classes will be defined with COM data types.

The ActiveX component I need to reverse engineer does not show up on the Selection of Project Items page of the Reverse Engineering Wizard.

To add an ActiveX component to your Visual Basic project and to the Selection of Project Items page of the Reverse Engineering Wizard, click References from the Project menu in Visual Basic and select the missing ActiveX component.

Some of the methods and data members that I reverse engineered did not show up in the model. Why?

Those methods and data members probably contained some syntax error. Before reverse engineering a Visual Basic project, make sure that it does not contain any syntax errors by compiling the code.

When reverse engineering my project, the enum declarations do not show up in the model, even though some reverse engineered components in the same model contain classes with the stereotype “enum”. Why?

Currently, enum declarations can only be reverse engineered from ActiveX components and type libraries, not from Visual Basic projects. Also, note that Visual Modeler cannot generate enum declarations.

When reverse engineering a class module, all code comments, even those that are not relevant in the model, show up in the Documentation field of the generated model elements. How do I avoid this to happen?

or

When reverse engineering a class module, the code comments do not show up in the Documentation field of the generated model elements. What is wrong?

For each declaration in the Visual Basic code, Visual Modeler copies the directly preceding comment into the documentation field of the corresponding model element in Visual Modeler. Thus, to make a specific comment appear in the documentation field, make sure it is located before the declaration and that there are no empty lines between the comment and the declaration. On the other hand, to avoid generating a specific comment into the model, insert an empty line or put the comment after the declaration.

How can I share the source code for a component (e.g. a DLL) between two models without affecting the model IDs in the component when reverse engineering it?

When reverse engineering Visual Basic code, Visual Modeler generates and inserts a unique model ID for each new member declaration, both into the model and into the code. If the same piece of code is reverse engineered into another model, Visual Modeler regards each member declaration as new again, and assigns new model IDs for them, both in the model and in the shared code. To keep the original model IDs in the code, reverse engineer the component into your model, but do not save the Visual Basic project where the component is implemented.

When reverse engineering a new collection class, Visual Modeler does not create any relationship with its contained class in the model. Why?

The data member declarations in the collection class do not contain enough information for Visual Modeler to automatically create such a relationship. You have to create it manually in the model.


Visual Basic Integration - FAQ

The Visual Modeler submenu is not available on the Add-Ins menu in Visual Basic. What shall I do?

In Microsoft Visual Basic, select Add-In Manager from the Add-Ins menu. Make sure both of the Visual Modeler add-ins are selected. They are called ”Visual Modeler Menus Addin” and “Visual Modeler Addin”. If any of them are completely missing, open the vbaddin.ini file, which is located in the Windows folder, and add the following two lines:

RVBAddInMenus.Connector=1

RVBAddIn.Connector=1

If the Visual Modeler submenu still is missing, contact technical support.

Visual Modeler displays the error message “VB not installed” even though VB is installed. Why?

If you have never run the Microsoft Visual Basic application after installing it, Visual Modeler might not be able to localize the installation. In that case, run the Microsoft Visual Basic application once.


Browse Class Diagrams (Add-Ins:Visual Modeler Menu) - VB

This command is located on the Add-Ins menu in Microsoft Visual Basic. Use the command to traverse from the selected project item in Visual Basic to the class diagrams in Visual Modeler where the corresponding model element occurs.

If Visual Modeler is not running and/or if the model where the selected project item is defined is not open, Visual Modeler is started and the corresponding model is opened. If there is no corresponding model for the project, the command looks for the project item in the current open model.


Revert to Last Saved (Visual Basic:Tools Menu) - VB

Use this command to revert to the last saved version of the current model and Visual Basic project. Note that Visual Modeler then overwrites the contents of the current open model and project.

You can use this command in combination with the Save model and project… option in the Code Generation and Reverse Engineering Wizards. Thus, when the Wizard is finished, and if you are not satisfied with the generated result, you can use the Revert to Last Saved command to revert to the saved model and project.


Import VB6 Classes (Visual Basic:Tools Menu) - VB

Use this command to import the classes in the VB6 type library into the model. The command creates a logical package, called VB6, containing interfaces for the classes that are found in the VB6 type library. The command also creates a component, called VB6, in the component view. Use the imported classes to show how the classes of your model depend on the classes in VB6.

Note: The difference between importing and reverse engineering VB6, is that the Import command does not create any methods and properties on the classes.


This help file contains context sensitive help for Visual Modeler.


Source Code (Browse Menu)

Use this command to traverse from selected model elements to their corresponding project items.


Assign to New Component (Tools Menu)

Use this command to create a new component and assign the selected classes to the new component. Visual Modeler displays a dialog box where you can select the appropriate component type.


Generate Code (Tools Menu)

Use the Generate Code command to create a new project from a component in the current model, or to update a project with changes made to a component in the model. The command generates code from the selected classes, or from all classes that are assigned to the selected components.

If the Generate Code command detects either of these problems:

•	nothing was selected

•	there are no classes assigned to a selected component

•	a selected class is not assigned to any component

•	there is no component in the model

•	a selected component does not have an implementation language

Visual Modeler solves the problem or displays an error message explaining what you have to do before you can generate code from the selection.

Note: If the selected classes are all assigned to the same component, Visual Modeler automatically assigns any selected unassigned classes to that component before generating code.


Progress Dialog Box

This dialog box informs you about the progress of the operation.

•	To view the result, wait until the operation is finished. A Summary dialog box then displays the result.

•	To abort the operation, click Stop.


Summary Dialog Box

This dialog box displays the result of the operation on the following tabs:

•	Summary tab - shows a summary of what was created and updated as a result of the operation.

•	Log tab - lists any errors and/or warnings. You can open the log later by selecting Log from the Window menu.


Shows a summary of what was created and updated as a result of the operation.


Lists any errors and/or warnings. You can open the log later by selecting Log from the Window menu.


Closes the dialog box and exits.


Displays help on the dialog box.


Class Wizard (Tools Menu)

Use this command to get help when creating a new class. Follow the detailed instructions given in the different dialog boxes to document and specify information about the new class. The information you can specify is the name of the class, a textual description, service layer belonging, inherited classes, properties, and methods of the class. The new class will be inserted in the “Package Overview” diagrams and the “Three-Tiered Service Model” diagram of the model, as well as in the browser.

Select any field to get more information:

Tips

All information you have entered about the new class is saved in the class’ specification. To open the specification of the created class, select the class in the Browser or in a diagram and choose Specification from the Browse menu.


Provides a space for you to enter the name of the new class.


Class Wizard - Documentation

In this dialog box you are able to document the purpose and responsibilities of the new class by giving the class a type and writing a textual description of the class in the text box.

Select any field to get more information:

Tips

The text you enter is saved in the class’ specification when the class is created. To open the specification later, select the class in the Browser or in a diagram and choose Specification from the Browse menu.


Provides a space for you to write a textual description of the new class.


Provides a field for you to define the type of the new class. Select one of the predefined types or create a new one by entering the name of the new stereotype.


Class Wizard - Service Type

In this dialog box you define which fundamental service layer the new class belongs. You are also able to assign the new class to one of the logical packages in the selected service layer. If you do not assign the class to a package, it is placed on the top-level of the selected service layer.

•	To define which service layer the new class belongs, click User Services, Business Services, Data Services, or Other if none of the predefined service layers are applicable.

•	To assign the new class to one of the logical packages in the selected service layer, select the package in the list below the service layer types.

•	To continue describing the new class, click Next>.

•	To create the new class and exit the Class Wizard, click Finish.

Select any field to get more information:

Tips

To change the selection later when the class has been created, you can drag-and-drop the class into another service layer in the Browser.


Specify the service layer to which the new class belongs: User Services, Business Services, Data Services, or “Other” if none of the fundamental service layers are applicable.


User Services Definition

User services provide the visual interface for presenting information and gathering data. They also secure the business services needed to deliver the required business capabilities and integrate the user with the applications to perform a business process.


Business Services Definition

Business services are the bridge between user and data services. They respond to requests from the user (or other business services) to execute a business task. They accomplish this by applying formal procedures and business rules to the relevant data. When the needed data resides on a database server, they secure the data services needed to accomplish the business task or apply the business rule. This protocol insulates the user from direct interaction with the database. Because business rules tend to change more frequently than the specific business tasks they support, they are ideal candidates for encapsulating in components that are physical separate from the application logic itself.


Data Services Definition

Data services maintain, access, and update data. They also manage and satisfy requests to manipulate data that are initiated by business services. Separating data services allows the data structure and access mechanisms to be maintained, modified, or, if necessary, even rearchitected without affecting business or user services.


Lists the logical packages that belong to the selected service layer. Note that a package may contain other packages.

To select the package to where the new class belongs, open the packages by clicking on the “+” sign in front of their names until you find the correct package. Select it and click Next>.


Class Wizard - Inheritance

In this dialog box you are able to specify if the new class inherits the implementation and/or the interface of other classes. This is the same as defining generalization relationships to superclasses.

Note that this step is optional. To skip this step, click Next>. Otherwise, select Yes.

To select a class from which the new class inherits:

1.	Click on the “+” sign to open the logical package to where the class belongs.

2.	Select the class in the left list and click Add>. A generalization relationship will then be created between the new class and the selected class.

Dialog Box

Select any field to get more information:


Specify whether the class inherits from other classes or not.


Adds the selected class to the list of inherited classes. That is, creates a generalization relationships between the new class and the selected class.

Selecting a class and clicking the Add> button is the same as first selecting the class and then clicking on it.


Removes the selected class from the list of inherited classes. Selecting a class and clicking the <Remove button is the same as first selecting the class and then clicking on the class.


Lists the classes from which the new class can inherit.

To select a class from which the new class inherits, click the Yes button, select the appropriate class in the left list, and click Add>.


Lists all currently inherited classes.

•	To add a class to this list, click the Yes button, select the class in the left list, and click Add>.

•	To deselect an added class, select the class in the right list and click <Remove.


Class Wizard - Methods

In this dialog box you are able to create methods of the new class. If you find it too early to define the methods of the new class, skip this step by clicking Next>. You can create the class’ methods later, when you know more about the behavior of the class.

To create a method in the Class Wizard:

1.	In the Methods list, click the right mouse button and select Insert. A new method is added to the new class.

2.	With the new method selected, give the new method a name in the Name field on the General tab.

3.	Make sure that the programming language in which the class will be implemented is selected in the Fundamental types language field. Define the method’s return type by selecting a type from the Return type combo box on the General tab. (The available return types correspond to the fundamental data types of the selected programming language.)

4.	Write a textual description of the method in the Documentation field on the General tab.

To delete a method in the Class Wizard:

1.	In the Methods list, select the method in question.

2.	Click the right mouse button and select Delete.

To create arguments/parameters to a method:

1.	Select the method and click on the Arguments tab.

2.	In the Methods list, click the right mouse button and select Insert. A new argument is then added.

3.	Give the argument a name in the Name text box.

4.	Make sure that the programming language in which the class will be implemented is selected in the Fundamental types language field. Select the type of the new argument from the Type combo box. (The available types correspond to the fundamental data types of the selected programming language.)

To change the order between the arguments, select the argument you wish to move and click on the arrows to move it up/down in the argument list.

Later, in the Specification dialog box for the method, you can assign initial values to the arguments.

Dialog Box

Select any field to get more information:


Specifies in which programming language the new class will be implemented. The Class Wizard uses the value of this field to display the appropriate set of fundamental types in the method Return type, method argument Type, and property Type combo boxes.


Lists the methods of the new class:

•	To create a method, click the right mouse button and select Insert. Name and describe the method on the General tab. Create arguments to the method on the Arguments tab.

•	To delete a selected method, click the right mouse button and select Delete.


Provides fields for you to specify a name and return type of a selected method, and to write a short description of the method:

•	To give the method a name, write the name in the Name field. The new name then turns up in the Methods list.

•	To give the method a return type, select the programming language in which the new class will be implemented to display the available return types, and select the desired type in the Return type combo box.


Provides fields for you to create arguments/parameters of a selected method:

•	To create a new argument, click the right mouse button and select Insert.

•	To give the selected argument a name, enter the name in the Name text box.

•	To give the selected argument a type, select the programming language in which the new class will be implemented. Then select the desired type in the Type combo box.

•	To delete an argument, click the right mouse button and select Delete.

•	To change the order between the arguments, select the argument you wish to move and click on the arrows to move it up/down in the argument list.


Class Wizard - Properties

In this dialog box you are able to create properties of the new class. If you find it too early to define the properties of the new class, skip this step by clicking Next>. You can create the class’ properties later, when you know more about the class.

To create a property in the Class Wizard:

1.	In the Properties list, click the right mouse button and select Insert. A new property is added to the new class.

2.	Make sure that the new property is selected. Give the new property a name in the Name field.

3.	Define the property’s type by selecting a type from the Type combo box on the General tab. The available return types correspond to the fundamental data types in the programming language that was chosen on the previous page.

4.	Optionally, give the property an initial value in the Initial value text box.

5.	Write a textual description of the property in the Documentation field.

To delete a property in the Class Wizard:

1.	In the Properties list, select the property to be deleted.

2.	Then click the right mouse button and select Delete.

Dialog Box

Select any field to get more information:


Lists the properties the new class. Each property is specified by its name, type, and optionally an initial value.

•	To create a property, click the right mouse button and select Insert. Name and describe the new property in the Property specification text boxes to the right.

•	To delete a selected property, click the right mouse button and select Delete.


Provides fields for you to give a name and type to a selected property and to write a short description of the property:

•	To give the property a name, write the name in the Name field. The new name then turns up in the Properties list.

•	To give the property a type, select the desired type in the Type combo box. The available types correspond to the fundamental data types of the language that was selected on the previous page.


Class Wizard - Summary

This dialog box shows a summary of your specification of the new class.

•	To create the class according to the specification shown, click Finish.

•	To change something before creating the class, click <Back until you find the desired dialog box. Change the specification and click Finish in any of the dialog boxes.

•	To exit the Class Wizard without creating the class, click Cancel.

Dialog Box

Select any field to get more information:


Shows a summary of the new class.


Displays help on the Class Wizard.


Closes the Wizard without generating or changing anything.


Moves back one step.


Moves to the next step.


Creates the new class and adds it to the model.


Generating a New Visual Basic Project from a Model

To generate a new project from a model, perform the following steps:

1.	In the component view of the model, create a component for the new Visual Basic project and double-click on it to open its specification. On the General tab, select the appropriate component stereotype and Visual Basic as implementation language.

2.	On the Realizes tab of the component specification, select Show all classes. Assign the classes that belong to the new component, by selecting each class in the list and clicking Assign on the context menu.

3.	Select the new component and choose Generate Code from the Tools menu. The Code Generation Wizard starts. (If the Welcome dialog box is shown, click Next>.)

Note: Step 1-3 can be automated and replaced by one single step: “Select the classes that will belong to the new project, and choose Generate Code from the Tools menu.” Visual Modeler then creates a component of a chosen type and assigns the selected classes to the new component before starting the Code Generation Wizard.

4.	The Select Classes dialog box is displayed.

5.	Click Next>. The Preview Classes dialog box is shown, from which you can preview and define the mapping to Visual Basic. It is recommended that you preview each new class. See Previewing a Class.

6.	When you are satisfied with all classes, click Next> in the Preview Classes dialog box. The General Options dialog box is then shown. (By selecting Save model and project before generating code, you can revert to the current versions after the code is generated with the Revert to Last Saved command on the Visual Basic submenu, which is located on the Tools menu.)

7.	Click Next>. The Finish dialog box is shown. Take a look at the code to be generated, and click Finish if you are satisfied, or <Back if you want to change something.

8.	Code generation starts and its progress is shown in the Progress dialog box. To abort the generation, click Stop. The code generator then completes the class module that is currently being created/updated before the generation is aborted.

9.	The result of the code generation is summarized in the Summary dialog box, which is displayed when the code generator has finished. The model-to-code mapping you defined during the preview step is stored in the specifications of the corresponding classes, properties, association roles and methods. The names of the created project files are stored in the ProjectFile model property of the generated components.

Be sure to review the generated source code before you continue modeling and coding.

See Also

Using Model Properties Other than those Available in the Code Generation Wizard

Generating a Class Together with its Collection Class

Generating Debug Code

Generating Error Handling Code

Generating “Add-Code Comments”


Updating a Visual Basic Project from Changes in a Model

1.	Open the model from which you want to generate code.

2.	If you have created any new classes that you want to add to the Visual Basic project that you are going to update, assign those classes to the component that corresponds to that Visual Basic project. (You can assign classes to components by using drag and drop, or with the Assign command on the Realizes tab of the component specification.)

3.	Select the component that corresponds to the Visual Basic project that you are going to update. Choose Generate Code from the Tools menu. (If the Welcome page is shown, click Next>.)

4.	The Select Classes dialog box is displayed, showing the model elements that are assigned to the selected component.

5.	Click Next>. The Preview Classes dialog box is shown, from which you can preview and define the mapping to Visual Basic. It is recommended that you preview at least each new class. See Previewing a Class.

6.	When you are satisfied with all classes, click Next> in the Preview Classes dialog box. The General Options dialog box is then shown. By selecting Save model and project before generating code, you can revert to the current versions after the code is generated with the Revert to Last Saved command on the Visual Basic submenu, which is located on the Tools menu.

7.	Click Next>. The Finish dialog box is shown. Take a look at the code to be generated, and click Finish if you are satisfied, or <Back if you want to change something.

8.	Code generation starts and its progress is shown in the Progress dialog box. To abort the generation, click Stop. The code generator then completes the class module that is currently being created/updated before the generation is aborted.

You have to confirm the deletion of Visual Basic project items, members, and methods whose corresponding classes, properties, roles, and method have been deleted in the model. Note that you will also have to confirm the continuous existence of project items, members and methods that are not supposed to have any correspondences in the model.

9. 	The result of the code generation is summarized in the Summary dialog box, which is displayed when the code generator has finished. The model-to-code mapping you defined during the preview step is stored in the specifications of the corresponding classes, properties, association roles and methods.

Be sure to review the generated source code before you continue modeling and coding.

See Also

Using Model Properties Other Than Those Available in the Code Generation Wizard

Generating a Class Together with its Collection Class

Generating Debug Code

Generating Error Handling Code

Generating “Add-Code Comments”

ProjectFile Model Property


Using Model Properties Other than those Available in the Code Generation Wizard

The Code Generation Wizard lets you define the most common and important model properties. The model properties for a class, property, association, or method are also available on the Visual Basic tab in its specification dialog. There you can view and change all the properties. By default, a predefined model property set is attached to a new model element. On the Visual Basic tab you can change to another set.

To modify model properties other than those available in the Code Generation Wizard, or attach another model property set, use the Visual Basic tab of the specification dialog boxes. The Visual Basic tab can be quickly opened by selecting a model element and pressing F4.

Note that modifying model properties other than those available in the Code Generation Wizard has to be done before executing the Code Generation Wizard.

See Also

Visual Basic Model Properties Overview.

For general information about model properties and how to modify them outside the Code Generation Wizard, please refer to the Index or Contents tab of the on-line help.


Previewing a Class - VB

From the Preview Classes dialog box, the Code Generation Wizard lets you preview and control the code to be generated for each class and its properties, roles, and methods. It is recommended that you preview each new class.

To preview a class:

1.	Select the class and click Preview.

2.	Define its mapping to Visual Basic code in the model properties dialog boxes. To get help, click Help or place the focus on any field and click F1.

The different option dialog boxes are:

•	The Class Options dialog box, where you define the instantiation rules and the collection class. (This is only applicable to class modules.)

•	The Property and Role Options dialog boxes, where you assign Set, Get and Let procedures to the data members generated for the class’ properties and association roles.

•	The Method Options dialog box, where you define the generated method as “Sub or Function”, a “DLL linked method”, or a “Property Get, Set or Let operation”.

3.	When you are satisfied with a class, click Finish.


Selecting the Type of Project Item to Generate for a Class - VB

By default, a new class is considered to correspond to a class module in Visual Basic. That is, the stereotype of a new class is set to “Class Module”, which means that Visual Modeler by default produces a class module for a new class.

For classes that should be generated as other things in Visual Basic, or never be generated, you have to change their stereotype. Before you start the Code Generation Wizard, do as follows for each such class:

1. 	Open the specification for the class, by double-clicking the class.

2. 	On the General tab, click the arrow in the stereotype field to obtain a combo box with the available stereotypes.

3. 	Select the stereotype that corresponds to the implementation type of the class.

Note: Once you have generated a class you cannot alter its implementation type in Visual Modeler. To change, for example, a class module into a module, create a module in Microsoft Visual Basic and copy the methods and properties from the class module into the new module. Then delete the class module and reverse engineer the changes into the model.


Generating Debug Code - VB

To instruct the code generator to insert conditionally compiled debug code for Initialize and Terminate events for the selected classes, select Include Debug Code in Initialize and Terminate Events on the General Options page in the Code Generation Wizard.

To remove generated debug code for a class, you have to manually update the corresponding code.

The following debug code is inserted for the generated classes if the Include Debug Code in Initialize and Terminate Events is selected:

#Const DebugMode = 1

#If DebugMode Then

Private mlClassDebugID As Long

#End If

Private Sub Class_Initialize()

#If DebugMode Then

mlClassDebugID = GetNextClassDebugID()

Debug.Print “’” & TypeName(Me) & “’ instance “

& mlClassDebugID & “ created”

#End If

End Sub

Private Sub Class_Terminate()

#If DebugMode Then

Debug.Print “’” & TypeName(Me) & “’ instance “

& CStr(mlClassDebugID) & “ is terminating”

#End If

End Sub

#If DebugMode Then

Public Property Get ClassDebugID()

ClassDebugID = mlClassDebugID

End Property

#End If

End Sub


Generating Error Handling Code - VB

To instruct the code generator to add error-handling code in the generated methods, select Include Err.Raise in All Generated Procedures on the General Options page in the Code Generation Wizard. This option applies to methods that are generated for the first time.

To remove generated error handling code for a class, you have to manually update the corresponding code.

By default, Visual Modeler generates the following error handling code for each new method when Include Err.Raise in All Generated Procedures is selected:

Public Function AlfaMethod() As Integer

On Error GoTo AlfaMethodErr

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End Function

To include other error handling code than the code generated by default, you can write your own code in the EntryCode and ExitCode model properties for the method. Visual Modeler inserts the code specified by the EntryCode and ExitCode model properties regardless of the value of the Include Err.Raise in All Generated Procedures option.


Generating "Add-Code Comments" - VB
Generating “Add-Code Comments” - VB

To instruct the code generator to generate comments indicating where you need to add code in each method, select Include Comments on the General Options page in the Code Generation Wizard. This option applies to methods that are generated for the first time.

Example of “add-code comments”:

Public Sub NewMethod()

    'your code goes here...

End Sub


Naming Data Members - VB

When previewing the code for a role or property in the Code Generation Wizard, you are able to define a lot of details about its mapping to Visual Basic code. However, if you need to change the name of a generated data member you have to do it in the specification of the corresponding role or property, before entering the Code Generation Wizard.

For information on the naming principles and how to change the default name, please refer to the DataMemberName and NameIfUnlabeled model properties.


Reviewing the Generated Visual Basic Code

1.	Check the error log, on the Log tab in the Summary dialog box of the Code Generation Wizard to track down errors and warnings. Or, open the log by selecting Log on the Window menu in Visual Modeler.

2.	Compile the project to make sure that the generated code is free from syntax errors.

3.	Inspect the generated source code in your Microsoft Visual Basic environment. There are two commands that are helpful when inspecting the correspondence between the code and the model:

In Visual Modeler, the Source Code command on the Browse menu takes you to the Visual Basic class module with the same name as the selected class in the model.

In Microsoft Visual Basic, from the Add-Ins menu, point to Visual Modeler and click Browse Class Diagram to display a list of all class diagrams in which the selected Visual Basic class module appears. Select the diagram you want to open.

4.	Based on your evaluation, make the necessary changes to the model and/or to the model properties, and regenerate the code, or make the changes directly in the code. Or, if needed, revert to the previous version of the project by clicking Revert to Last Saved on the Visual Basic submenu, which is located on the Tools menu in Visual Modeler.

5.	When you are satisfied, save the code in your Microsoft Visual Basic environment.


Code Generation Wizard

Use the Generate Code command to create Visual Basic project(s) from component(s) in the current model, or to update the Visual Basic project(s) that correspond to component(s) in the model. The command generates code from the components that were explicitly selected as well as the components to which any selected classes are assigned.

The command starts the Code Generation Wizard, where you can preview and define the mapping between the selected classes, their properties, roles, and methods, and Visual Basic code or accept the suggested default mapping. When you are finished, the Code Generation Wizard updates or creates code corresponding to the selected classes and your mappings.

If Visual Modeler detects either of these problems:

•	nothing was selected

•	there are no classes assigned to a selected component

•	a selected class is not assigned to any component

•	there is no component in the model

•	a selected component does not have an implementation language

•	the selected components have different implementation languages

Visual Modeler resolves the problem or displays an error message explaining what you have to do before you can generate code from the selection.

See Also

Generating a New Visual Basic Project from a Model

Updating a Visual Basic Project from Changes in a Model

Visual Basic Model Properties Overview


Code Generation Wizard - Select Classes

In this dialog box, you select the classes from which you want to generate code.

Select the model elements from which you want to generate code—all new and changed classes for example. By default, the model elements that were selected in the browser and/or in diagrams are selected already.

Do any of the following:

•	To select a class, click on the “+” sign to open the package to where the class belongs. Select the class in the Classes in model list and click Add>.

•	To deselect a class, select the class in the Selected classes list and click <Remove.

•	To preview the code to be generated and change each class’s mapping to Visual Basic code, click Next>.

•	To generate code with the current model property settings, click Finish.

Dialog Box

Click on a field to get more information:


Lists the model elements from which you can generate code. This means that only classes of the type “Class Module” are shown in the list.

•	To select a class, click on the “+” sign to open the logical package to where the class belongs. Select the class in the Classes in model list and click Add>.


Lists all currently selected classes. Initially, it contains all classes that were selected in the browser and/or in diagrams before entering the Code Generation Wizard. For each class in the list, the name of the component to which the class is assigned is appended to its name.

•	To add a class to the Selected classes list, click on the “+” sign to open the logical package to where the class belongs. Select the class in the Classes in model list and click Add>.

•	To deselect an added class, select the class in the Selected classes list and click <Remove.


Adds the selected class to the set of selected classes. Selecting a class and clicking the Add> button is the same as first selecting the class and then clicking on it.


Removes the selected class from the set of selected classes. Selecting a class and clicking the <Remove button is the same as first selecting the class and then clicking on it.


Adds all classes from the Classes in model list to the set of selected classes.


Removes all classes from the set of selected classes.


Code Generation Wizard - Preview Classes

In this dialog box you can ask for a code preview of the classes from which you have chosen to generate code. During that preview you are able to change and refine the code to be generated for each class, its properties, association roles, and methods. For example, you can define Property Get, Let, and/or Set procedures for the class’ properties and define the type of each method.

It is strongly recommended that you preview all classes that are to be generated for the first time. The more detailed code mapping you are able to do, the more of the coding can be automated.

Do any of the following:

•	To preview a class, select the class and click Preview. Define its mapping to Visual Basic code in the four dialog boxes: Class Options (only for class modules), Property Options, Role Options, and Method Options. When you are finished with the preview of a class, click Finish in one of the preview dialog boxes.

•	To define general code-generation instructions, for example, whether or not to insert debug code, comments, and error-handling code, click Next>.

•	To generate code with the current general instruction values, click Finish.

Note: To simplify, the preview lets you define only the most common and important model properties. You can change other properties on the Visual Basic tab on the specification dialog boxes before running the Code Generation Wizard.

Dialog Box

Click on a field to get more information:


Lists the classes from which you have chosen to generate code. The Component field indicates to which component a class is assigned.

•	To get a preview of the code to be generated for one of the classes, select the class and click Preview. You should preview at least all new classes before starting the code generation.


Shows, in a number of dialog boxes, a preview of the code to be generated for a selected class.


Code Generation Wizard - Class Options

In this dialog box you define the model properties for the class as a whole. Click Next> to move on to the next dialog box or click Finish to generate the code corresponding to the current setting. This dialog box is only relevant for classes defined to be generated as class modules.

Select any field for more information:

See Also

Model Properties for Classes.

Code Generated for Classes.


Specifies whether the class is visible outside the project or not, and if so, specifies rules for how it may be instantiated from other projects (see Creatable).


Provides a space for you to enter the name of the collection class to be used for data members generated for the class, when the multiplicity is unbounded and larger than one. See Collection Class. By default, the class “Collection” is used for this.

If the named collection class does not exist yet, you can generate it by selecting Generate New Collection Classes when you get to the General Options dialog box of the Code Generation Wizard.


Code Generation Wizard - Property Options

In this dialog box you define model properties for each property of the class. Click Next> to move on to the next dialog box or click Finish to generate the code corresponding to the current setting.

Select any field for more information:

See Also

Model Properties for Properties.

Properties and Visual Basic.


Lists the class properties of the selected class.


Shows a preview of the code that will be generated for the selected class properties from the current setting.


Defines whether or not to generate code for the selected class property.

With Generate selected, the declaration of the generated variable can be defined by selecting the appropriate model properties, such as Constant, New, and/or WithEvent.

Note: Constant is disabled if the selected class property does not have an initial value assigned.

For a property of the type array, the size of the generated array is defined in the Array bounds box. To generate correct code you must use Visual Basic syntax for array bound values, for example "1 To 10" or "1 To MaxLen" (see Subscript). Note that the Wizard automatically inserts the parenthesis.


Specifies if property Get, Set, and/or Let procedures are needed for the selected class property. See GenerateGet/Set/LetOperation.


Code Generation Wizard - Role Options

In this dialog box you define model properties for each role of the class.

Click Next> to move on to the next dialog box or click Finish to generate the code corresponding to the current setting.

Select any field for more information:

See Also

Model Properties for Roles.

Association Relationships.


Lists the roles defined for the selected class.


Shows a preview of the code that will be generated for the selected role from the current setting.


Specifies whether to generate code or not for the association. If so, the exact declaration of the variable is defined by selecting the appropriate variable options, New and/or WithEvent.

For a relationship with a fix multiplicity larger than one, define the size of the generated array in the Array bounds box. To generate correct code you must use Visual Basic syntax for array bound values, for example "1 To 10" or "1 To MaxLen" (see Subscript). Note that the Wizard automatically inserts the parenthesis.


Specifies if property Get, Set, and/or Let procedures are needed for the association. See GenerateGet/Set/LetOperation.


Code Generation Wizard - Method Options

In this dialog box you define model properties for each method of the class. Click Next> to move on to the next dialog box or click Finish to generate the code corresponding to the current setting. Select any field for more information:

See Also

Model Properties for User-Defined Methods.

User-Defined Methods and Visual Basic.


Lists the methods of the selected class, including the method return types.


Shows a preview of the code that will be generated for the selected method from the current option setting.


Specifies the kind of selected method (see Stereotypes of Methods).


Specifies whether the selected method is static or not (see IsStatic).


Provides a space for you to specify to which DLL library the method belongs (see Library Name) as well as the real name of the method if you are using an alias (see Alias Name). This is only relevant for methods of the type "DDL Sub or Function".


Code Generation Wizard - General Options

In this dialog box, you can select general model properties that apply to several selected classes or to the entire model and project.

Some of these options allow you include predefined code structures in classes and methods that are generated for the first time. The Generate new collection classes option allows you to create the collection classes that are referred to on the Class Options pages.

Also, you can choose to save the model and project before generating any code. Note that Visual Modeler not only updates the current Visual Basic project when generating code, but also can affect the model. For example, Visual Modeler saves the current values of the model properties and creates new collection classes in the model (if any).

Click Finish to generate code corresponding to the current settings for model properties.

Select any field for more information:


Specifies whether or not to save the current open model and project before generating anything. When the Wizard is finished, and if you are not satisfied with the generated result, you can revert to the saved model and project by choosing the Revert to Last Saved command on the Visual Basic submenu, which is found on the Tools menu.

Note: Visual Modeler not only updates the current Visual Basic project when generating code, the model may also be affected. For example, Visual Modeler saves the current values of the model properties and creates new collection classes in the model (if any).


Specifies whether or not to include conditionally compiled debug code for Initialize and Terminate events for the generated classes.

Example of debug code inserted into a generated class:

#Const DebugMode = 1

#If DebugMode Then

Private mlClassDebugID As Long

#End If

Private Sub Class_Initialize()

#If DebugMode Then

mlClassDebugID = GetNextClassDebugID()

Debug.Print “’” & TypeName(Me) & “’ instance “

& mlClassDebugID & “ created”

#End If

End Sub

Private Sub Class_Terminate()

#If DebugMode Then

Debug.Print “’” & TypeName(Me) & “’ instance “

& CStr(mlClassDebugID) & “ is terminating”

#End If

End Sub

#If DebugMode Then

Public Property Get ClassDebugID()

ClassDebugID = mlClassDebugID

End Property

#End If


Specifies whether or not to add error handling code in the generated code. This option applies to methods that are generated for the first time.

Example of error handling code inserted into a generated method:

Public Function AlfaMethod() As Integer

On Error GoTo AlfaMethodErr

AlfaMethodErr:

Call RaiseError(MyUnhandledError, “Alfa:AlfaMethod Method”)

End Function


Specifies whether or not to generate comments indicating where you need to add code. This option applies to methods that are generated for the first time.

Example of “add-code comments” inserted into a generated method:

Public Sub NewMethod()

‘your code goes here..

End Sub


Specifies whether or not to generate collection classes for any new collection classes you have defined in the Code Generation Wizard - Class Options dialog box. If you select this option, Visual Modeler generates each new collection class both as a class in the model and a class module in the Visual Basic project.


Code Generation Wizard - Finish

This dialog box lists the project items that will be generated.

•	To generate that code, click Finish.

•	To make changes in the code mapping or select other model elements, click <Back.

Select any field for more information:


Lists the project items that will be generated.


Delete Dialog Box

During code generation: This dialog box is shown because the Code Generation Wizard has detected some code elements that do not have any correspondences in the model. Synchronize the project with the model by deleting selected code elements from the project.

During reverse engineering: This dialog box is shown because the Reverse Engineering Wizard has detected some model elements that do not have any correspondences in the code. Synchronize the model with the project by deleting selected model elements from the model.

To select and delete items from the project (during code generation) or model (during reverse engineering):

1.	Use the Delete > and < Keep buttons to decide which items you want to delete from the project/model and which items you want to keep in the project/model.

2.	Click Next > and perform step 1 until you are finished with all the delete pages.

3.	Click OK. The selected items will then be deleted from the project (when generating code) or from the model (when reverse engineering).

Note: You can quickly move to a specific page in the Delete dialog, by clicking with the right mouse button on the < Previous or Next > button and selecting the appropriate page from the menu shown.


Adds the selected item to the set of items to be deleted. Selecting a class and clicking the Add> button is the same as first selecting the class and then clicking on it.


Removes the selected item from the set of items to be deleted. Selecting a class and clicking the <Remove button is the same as first selecting the class and then clicking on it.


Adds all listed items to the set of items to be deleted.


Removes all items from the set of items to be deleted.


Displays help on the Delete dialog box.


Deletes the selected items from the model/project.


Displays help on the Code Generation Wizard.


Generates Visual Basic code for the selected classes.


Exits the code preview for the class.


During code generation: Displays the code elements that do not have any correspondence in the current model. For example, the list may show all the class modules whose corresponding model classes that have been deleted from the model. Note that the list does not only show things that have been deleted from the model. It also shows code elements that never have had any model correspondence.

During reverse engineering: Displays any model elements that do not have any correspondence in the current Visual Basic project. For example, the list may show properties and methods that have been deleted from the corresponding Visual Basic class module. Note that the list does not only show things that have been deleted from the code. It also shows model elements that never have had any code correspondence.


Displays the classes or members that you have chosen to delete.


Closes the Wizard without generating or changing anything.


Moves back one step.


Moves to the next step.


Generating a New User-Defined Collection Class During Code Generation - VB

With the Code Generation Wizard you can generate collection classes and their corresponding classes at the same time. Take the following steps:

1.	Select the classes for which you want to generate collection classes. On the Tools menu, click Generate Code.

2.	Make sure that the classes for which you want to generate collection classes are selected. Click Next >. This takes you to the Preview dialog box. Perform step 3 and 4 for each selected class.

3.	Select a class and click Preview. The Class Options dialog box opens.

4.	Give the collection class a name in the Collection Class field and click Finish. (This has the same effect as entering the name of the collection class in the CollectionClass model property in the class’ specification.)

5.	Click Next >. The General Options dialog box opens.

6.	Select the Generate new collection classes option and click Finish to start the code generation.

To delete a created collection class from the model, select the collection class and choose Delete from Model from the Edit menu. Then reset the CollectionClass model property for the class that refers to the deleted collection class (in the Class Options dialog box of the Code Generation Wizard or on the Visual Basic tab of the class specification).


Assigning a New User-Defined Collection Class to a Class and Generate It Later - VB

To assign an existing user-defined collection class to a class, perform the following steps:

1.	Open the specification of the class.

2.	Select the Visual Basic tab.

3.	Enter the name of the new collection class in the value field of the CollectionClass property.

The next time you generate code for the class, the collection class will be created both in the model and in the code if it did not exist before.


Assigning an Existing Collection Class to a Class - VB

To assign a new user-defined collection class to a class, without generating the collection class at the same time, take the following steps:

1.	Open the specification of the class.

2.	Select the Visual Basic tab.

3.	Enter the name of the new collection class in the value field of the CollectionClass property.


Creating a New Model from a Visual Basic Project

1.	Start Microsoft Visual Basic and open the project you want to reverse engineer. Compile the project and make sure that the code does not contain any syntax errors.

2.	In Microsoft Visual Basic, choose Reverse Engineering Wizard from the Visual Modeler submenu, found on the Add-Ins menu.

3.	A dialog box is displayed with a list of any currently open models and any models that this project has been reverse engineered into before. Click New. Visual Modeler is started with an empty model loaded.

4.	The Selection of Project Items dialog box opens. Select the appropriate project items.

5.	Select Save model and project before reverse engineering if you want to be able to use the Revert to Last Saved command to revert to the current version of the project after the reverse engineering process. (The reason why the project is updated during reverse engineering is that Visual Modeler needs to insert unique model element identifiers as code comments.)

6.	To make the model easy to understand, each re-engineered class should be assigned to one of the logical packages in the model; either directly to one of the three service layer packages, or to a package inside one of the service layer packages. To do that, click Next>. The Assignment of Project Items dialog box opens.

7.	Assign each class, by dragging and dropping the corresponding project item onto its parent package in the Logical Packages list. You can also create new packages here if a specific class does not naturally belong to any of the existing packages. You can change the assignment later, in the model, or in the Reverse Engineering Wizard. Any unassigned classes will, by default, be assigned to a logical package named Unassigned.

8.	Click Finish. Classes, properties, associations and methods corresponding to the selected project items are inserted into your new model and main diagrams. All affected diagrams are opened.

9.	Save the new model. The name and location of the model file is then stored as a related document to the reverse engineered Visual Basic project.

After reverse engineering, you have a design model of your code. The first thing you should do is to layout the created diagrams to illustrate the architecture of the system. Avoid crossed association lines by moving the classes in the diagram, and use the Diagram Object Properties command on the Edit menu to control the level of class details in a diagram.

You can now further develop the model. Use the Create command on the Tools menu to create new model elements, and the ...Diagram commands on the Browse menu to create new diagrams.

See Also

Contents of a New Model

Visual Basic to Model Mapping


Updating an Existing Model - VB

1.	Compile the project and make sure that the Visual Basic project you are going to reverse engineer does not contain any syntax errors.

2.	In Microsoft Visual Basic, choose Reverse Engineering Wizard from the Visual Modeler submenu, found on the Add-Ins menu. A dialog box is displayed with a list of any currently open models and any models that this project has been reverse engineered into before. Select the appropriate model or browse for it. Visual Modeler is started, if needed, and the selected model is loaded.

3.	The Selection of Project Items dialog box for the chosen Visual Basic project opens. Select the project items you want to reverse engineer.

4.	By selecting Save model and project before reverse engineering, you can revert to the current versions of the model and project after the reverse engineering process, with the Revert to Last Saved command.

5.	For new project items, you should define to which logical packages the corresponding model classes shall belong. To do that click Next>. The Assignment of Project Items dialog box then opens.

6.	Assign each new class, by dragging and dropping the corresponding project item onto its parent package in the Logical Packages list. You can also create new packages here if a specific class does not naturally belong to any of the existing packages. You can change the assignment later, in the model, or in the Reverse Engineering Wizard. Any unassigned classes will, by default, be assigned to a logical package named Unassigned.

7.	Click Finish. The information about the classes, properties, associations, and methods that correspond to the selected project items are now updated in the model. New classes are added to the main diagrams, which are opened and displayed.

You have to confirm the deletion of classes, properties, roles, and methods whose corresponding project item, properties, roles, and methods have been deleted in the model. You also have to confirm the continuous existence of classes, properties, roles, and methods that are not supposed to have any correspondences in the project.

8.	Layout the updated diagrams and then save the new version of the model.

See Also

Visual Basic to Model Mapping


Importing VB Classes

To be able to show how the classes in your model depend on the classes in VB6, you can add the VB6 classes to your model. You can add them by reverse engineering VB6, but there is also a special command for it called Import VB6 Classes on the Visual Basic menu. This command is a quick way to import VB6 because it does not create any methods and properties on the interfaces.

To import the classes in VB6 into your model:

1.	Choose Visual Basic from the Tools menu, and click Import VB6 Classes.

2.	The command creates a component and a logical package, called VB6, containing the interface classes of VB6.


Adding External Components to a Model

To add an external software module to your model:

1.	Drag the software module (the .exe, .dll, .ocx, or .tlb file) from the Microsoft Visual Component Manager or from the Microsoft Explorer and drop it in an open component diagram, or on a component package or logical package in the browser.

2.	If the module contained all the necessary information (which is not always the case if you drag it from the Microsoft Explorer) the component is created in the following way:

•	If the drop target is a component package or one of its diagrams, the new component will belong to that package. Otherwise, the new component is added to the top-level of the Component View and to the main component diagram.

•	A logical package with the same name as the new component is created in the logical view. The new logical package contains the interface elements that are provided by the corresponding software module. The interface of the new component can now be used by the classes in the model.

•	If the drop target is a logical package or one of its diagrams, the logical package for the new component is added to that package.

Note: The difference between adding the ActiveX references of a project via drag and drop or via the Reverse Engineering Wizard, as described in Adding Components from a Visual Basic Project, is which set of fundamental data types the created interfaces will use. With drag and drop, the interfaces will use COM data types, and with reverse engineering the interfaces will use VB types.

Also, the differences between dragging and dropping a software module into a model and reverse engineering the corresponding project are that:

•	Drag and drop regards the component as external to the modeled application. That is, a component and the interfaces it provides are created in the model.

•	Reverse engineering makes the project part of the model. That is, the classes that implement the component, and not its interface, is reverse engineered into the model.


Adding Components from a Visual Basic Project

You can use the Reverse Engineering Wizard to add the Visual Basic components, which are referenced from a project, into the corresponding model. Perform as follows:

1.	In Visual Modeler, open the model to which you want to add the components.

2.	Choose Reverse Engineering Wizard from the Visual Basic submenu, which is located on the Tools menu. If the corresponding Visual Basic project is not opened, or if several projects are opened, select the Visual Basic project you want to reverse engineer in the displayed dialog box.

3.	The Selection of Project Items dialog box opens.

4.	Expand ActiveX References. That list displays the components that are referenced from the selected Visual Basic project. That is, it displays the components that are selected in the References dialog box found on the Project menu in Microsoft Visual Basic for the project. Select the ActiveX components you need.

5.	Click Next>. The Assignment of Project Items dialog box opens.

6.	Assign each selected ActiveX component to some place in the logical package structure, by dragging and dropping the corresponding code component onto its parent packages in the Logical Packages list. You can change the assignment later, in the model, or in the Reverse Engineering Wizard. (You can also create new packages here if a specific class does not naturally belong to any of the existing packages.)

By default, the selected components are assigned to the top level of the Logical View. That is, at the same level as the three service layer packages. You should place ActiveX components in a way that it is clear that these are reused components, and not classes that need to be implemented.

7.	Click Finish.

For each reverse engineered ActiveX component, Visual Modeler generates a logical package in the model, containing the component’s interfaces. As ActiveX components normally contain a lot of interface classes, it may take a while to reverse engineer them. However, you only need to re-engineer an ActiveX component once, because it will not likely change during development. Visual Modeler also creates a component with the same name as the ActiveX component in the component view.

Note: The difference between adding ActiveX references via drag and drop or via the Reverse Engineering Wizard, is which set of fundamental data types the created interfaces will use. With drag and drop, the interfaces will use COM data types, and with reverse engineering the interfaces will use VB types.

See Also

Visual Basic to Model Mapping


Reverse Engineering Wizard (Visual Basic:Tools Menu)

Use the Reverse Engineering Wizard when:

•	Creating a new model from a Visual Basic project.

•	Updating an existing model with changes made to the code.

•	Adding Visual Basic components to your model, for example adding the ActiveX components to be used.

Before reverse engineering a Visual Basic project, make sure that the code does not contain any syntax errors, by compiling the project.

In the Reverse Engineering Wizard, you select the project items you want to reverse engineer, and assign them to new or existing packages in the model. If you have deleted any members or methods from any of the selected classes, you will have to confirm the deletion of any corresponding properties, roles, and methods in the model.

The reverse engineering is performed between the current Visual Basic project, if only one project is open, and the current open model. If no project is open, or if several projects are open, the Reverse Engineering Wizard lets you select a project. If no model is open, the Reverse Engineering Wizard opens the model that corresponds to the selected project, if the project has been reverse engineered before or if it has been generated from a model. Otherwise, a new model is opened.

The Reverse Engineering Wizard command can be found both in Visual Modeler, on Visual Basic submenu of the Tools menu, and in Microsoft Visual Basic on the Add-Ins menu.

See Also

Visual Basic to Model Mapping


Reverse Engineering Wizard - Selection of Project Items

In this dialog box, you select the project items that will be subjected to reverse engineering.

To select project items:

1.	Select the project items to be used when updating your model. To select all project items in a folder, select the check box next to the folder. To select a specific project item, open the folder where it belongs by clicking the “+” sign, and then select the check box next to its name.

2.	If you want to define to which packages the generated model classes will belong, click Next>.

3.	Otherwise, click Finish. New classes are inserted by default at the top level of the model.

Dialog Box

Select any field to get more information:


Specifies whether or not to save the current open model and its corresponding Visual Basic project before reverse engineering. When the Wizard is finished, and if you are not satisfied with the result, you can revert to the saved model and project by choosing the Revert to Last Saved command on the Visual Basic submenu, found on the Tools menu.

Note: The Reverse Engineering Wizard not only updates the model. For every new class, property, role, or method that the Wizard creates in the model, it also adds a code annotation to the corresponding item in the Visual Basic project. The code annotation contains an identifier that Visual Modeler needs to uniquely identify the model element.


Lists the items in the current Visual Basic project. Select the project items you want to reverse engineer:

•	To select all project items in a folder, select the check box next to the folder.

•	To select a specific project item, open the folder where it belongs by clicking the + sign, then select the check box next to its name.


Reverse Engineering Wizard - Assignment of Project Items

In this dialog box you can assign the project items, which you selected in the previous dialog box, Selection of Project Items, to existing logical packages in the model or even create new logical packages. When you assign a project item to a package, the generated model element will belong to that package in the model.

You do not have to assign the project items. New classes will, by default, be assigned to a logical package named Unassigned. If you are satisfied with that, skip this step and click Finish.

For further information, click on a procedure below:

To assign a project item (and the corresponding model component) to a logical package

To reassign a project item (and the corresponding model component) to another logical package

To deassign a project item

To create a new package

Dialog Box

Select any field to get more information:


Assigning a Project Item to a Package

1.	See to it that the logical package in question is shown in the Logical packages list.

2.	In the Selected project items list, select the project item in question.

3.	Drag and drop the project item onto its parent package in the Logical packages list or to the Assigned project items list if the package already is selected.


Reassigning a Project Item to another Package

1.	See to it that the logical package in question is shown in the Logical packages list.

2.	In the Selected project items list or in the Assigned project items list, select the project item in question.

3.	Drag and drop the project item onto its parent package in the Logical packages list.


Deassigning a Project Item

1.	In the Assigned project items list, select the project item in question.

2.	Drag and drop the project item into the Selected project items list.


Creating New Packages
Creating a New Package

1.	In the Logical packages list, select the parent package and press the right mouse button.

2.	Choose New from the pop-up menu.

3.	Select and name the new logical package.

If you do not want to create new packages at this time, you can do it in Visual Modeler before you start the Reverse Engineering Wizard or after the reverse engineering.


Lists the name and type of the project item to reverse engineer. That is, the project items you have selected in the previous dialog box. The right field states whether a project item is assigned or not.

To assign a selected project item to a logical package, drag and drop the project item onto its parent package in the Logical packages list.


Lists the logical package hierarchy of the current model. To expand the list, click on the "+" sign.

You can create new packages here with the New command on the right mouse button.


Lists the project items assigned to a selected package.

To remove a project item from the list, simply drag and drop it anywhere in the Selected project items list.


Reverse Engineering Wizard - Finish

In this dialog box you can see a list of the project items that will be reverse engineered, how many data members that will be generated or updated for each one of them, and how long the reverse engineering will take.

If you are satisfied with your selections, click Finish. Then the reverse engineering is performed and your model is updated.

Otherwise, click <Back to go back to the Selection of Project Items dialog box, where you can alter your selections.


Lists the project items that will be reverse engineered.


Displays help on the Reverse Engineering Wizard.


Updates the model from the selected project items.


Visual Basic to Model Mapping Overview

Click below to view the mapping rules used when reverse engineering Visual Basic code:

Visual Basic Projects

Class Modules, Forms, MDI Forms, Property Pages, User Documents, User Controls

Modules

ActiveX Components

Code Comments

Note: If your Visual Basic project contains conditional compiler directives, the reverse engineering applies only to those declarations that are visible under the current conditions. For example, if the project contains the compiler directive if Debug Dim A else Dim B endif, and Debug is true, then only the Dim B statement will be reverse engineered.


Reverse Engineering Visual Basic Projects

When reverse engineering a Visual Basic project, the following mapping rules are used:

In Visual Basic:	Becomes in the model:

Standard EXE project	A component with stereotype “EXE” and language “Visual Basic”.

ActiveX EXE project	A component with stereotype “ActiveX EXE” and language “Visual Basic”.

ActiveX DLL project	A component with stereotype “DLL” and language “Visual Basic”.

ActiveX Control project	A component with stereotype “ActiveX Control” and language “Visual Basic”.


Reverse Engineering Class Modules, Forms, MDI Forms, Property Pages, User Documents, User Controls - VB

When reverse engineering Visual Basic project items of the type class module, form, MDI form, property page, user document, or user control, the following mapping rules are used:

In Visual Basic:	Becomes in the model:

project_item_type	Class (stereotype = project_item_type)

Constant declaration	Property with default value

Data member	Property of a fundamental type

Association (navigable) to object type

Method	Method (stereotype = empty)

Event declaration	Method (stereotype = “Event”)

Property declaration	Method (stereotype = “Set”, “Get”, or “Let”)


Reverse Engineering Modules - VB

When reverse engineering Visual Basic modules, the following mapping rules are used:

In Visual Basic:	Becomes in the model:

Module	Class utility (stereotype = “Module”)

Constant declaration	Property with default value

Data member	Property of a fundamental type

Association (navigable) to object type

Method	Method (stereotype = empty)

Property declaration	Method (stereotype = “Set”, “Get”, or “Let”)


Reverse Engineering ActiveX Components - VB

When reverse engineering ActiveX components, the following mapping rules are used:

In Visual Basic:	Becomes in the model:

ActiveX component	A logical package in the logical view and a component, with stereotype “ActiveX”, in the component view

Class in an ActiveX	An interface item in the ActiveX’s logical package.

Constant declaration	Property with default value

Data member	Property of a fundamental type

Association (navigable) to object type

Method	Method (stereotype = empty)

Event declaration	Method (stereotype = “Event”)

Property Set or Let	Method (stereotype = “Set”, “Get”, or “Let”)

Property Get 	Association to the returned object type with object as return type


Reverse Engineering Code Comments - VB

Visual Modeler takes care of code comments by inserting them into the corresponding documentation fields in the model.

For each declaration in the Visual Basic code, Visual Modeler copies the directly preceding comment into the documentation field of the corresponding model element in Visual Modeler. Thus, you have to be careful where you put the code comments to make them appear in the correct model element.

Example:

' This comment will be inserted into the documentation field of the Purchaser property.

Public Property Get Purchaser() As Customer

    Purchaser = pPurchaser

End Property

' This comment will not be reverse engineered because there is an empty row between the comment and the function declaration below.

Public Sub Add_OrderRow( new_order_row As OrderRow)

    ' This comment will not be reverse engineered

     because it does not precede code that corresponds

     to a model component of its own.

    Orderrows.Add new_order_row

End Sub


Round-Trip Engineering Process for VB - Starting with a Model - VB
Round-Trip Engineering Process for VB - Starting with a Model

1.	Create a new model.

2.	Make a model of the system by creating logical packages, classes, relationships, properties, and methods, as well as by illustrating the model in diagrams.

3.	During design, if you realize that your system will be using other existing software modules, add those external components to the model so that you can show how the system depends on those components.

4.	Generate a new Visual Basic project from the model.

5.	Evolve the generated code.

6.	Reverse engineer the code to create a new version of the model.

7.	When including new references into the corresponding Visual Basic project, add those Visual Basic components to the model so that you can show how the system depends on those components.

8.	Modify the model.

9.	Update the Visual Basic project from changes in the model.

10.Continue developing your system in increments by iterating through step 5 - 9.

When further developing the application in one of the tools, remember to generate code or reverse engineer before continuing the development in the other tool. Otherwise, if you rename or delete classes, members, and methods in both tools at the same time, you may lose some of the changes.

Also, make sure that the code does not contain any syntax errors, by compiling the code before code generation or reverse engineering. If you generate or reverse engineer code with syntax errors, the result may not be as expected.

Moreover, be careful when moving methods from one class to another in the model, because the code generator regards moved methods as new methods. That is, their method bodies are initially empty.


Round-Trip Engineering Process - Starting with a Visual Basic Project

1.	Reverse engineer the project to create a new model.

2.	Modify the system model by creating new logical packages, classes, relationships, properties, and methods, as well as by illustrating the model in diagrams.

3.	Update the Visual Basic project from changes in the model.

4.	Evolve the generated code.

5.	Reverse engineer the project to update the model.

6.	Continue developing your system in increments by iterating through steps 2 - 5.

When further developing the application in one of the tools, remember to generate code or reverse engineer before continuing the development in the other tool. Otherwise, if you rename or delete classes, members, and methods in both tools at the same time, you may lose some of the changes.

Also, make sure that the code does not contain any syntax errors, by compiling the code before code generation or reverse engineering. If you generate or reverse engineer code with syntax errors, the result may not be as expected.

Moreover, be careful when moving methods from one class to another in the model, because the code generator regards moved methods as new methods. That is, their method bodies are initially empty.


Creating a New Model - VB

To create a new model, perform the following steps:

1.	On the File menu, click New. A new model is opened.

2.	To add the VB6 classes to your model, choose Visual Basic from the Tools menu, and then click Import VB6 Classes. If you do that, you can show how the new classes in the model are related to the VB6 classes, by creating relationships between them.

3.	Give the new model a name by choosing Save As from the File menu.

See Also

Contents of a New Model


Contents of a New Model - VB

A new model contains by default the following:

Logical View

The logical view describes the logical structure of the system, that is, the classes and their relationships. By default it contains the following:

•	Three logical packages representing the three fundamental service layers of a three-tiered model: User Services, Business Services, and Data Services.

•	For each service layer package, a class diagram, called Package Overview. Visual Modeler automatically inserts each new class, or package, into the “Package Overview” of the service layer to which it belongs

•	A three-tiered diagram called “Three-Tiered Service Model”. Visual Modeler automatically inserts each new class or logical package into this diagram, in the tier representing the service layer to which it belongs.

Component View

The component view describes the physical structure of the system, that is, how the system is divided into .exe files and DLLs. By connecting classes to components, and components to Visual Basic projects, the component view defines in which Visual Basic project(s) the classes in the model are implemented.

Deployment View

The deployment view shows the connections between the system’s nodes and the allocation of its processes to nodes. It contains by default:

•	A diagram called “Deployment Diagram”.


Evolving the Generated Code - VB

Evolve the generated Visual Basic source code by editing the code regions to implement the application’s functionality included in the iteration, and changing and adding data members (variables), constants, methods (functions, subs, and property procedures), forms, controls, and so on.

Compile, and test the edited project in the Visual Basic development environment. Make sure that the project does not contain any syntax errors before generating or reverse engineering code again.

When generating code, Visual Modeler uses the procedure separators in Visual Basic as indicators of where declarations start and end. Make sure that the separators are correctly located before generating code. For example, if there is an empty line before the endif statement of a compiler directive in Visual Basic, the location of the procedure separator becomes incorrect.

Important: For each generated project item, member, and method, Visual Modeler adds an identifier as a code comment (for example “ModelID=3237F8CE0053”), which identifies the corresponding class, property, role, or method in the model. Do not edit those identifiers!

See Also

Please refer to the documentation you received with your Visual Basic product for specific information on Visual Basic.


Visual Basic Stereotypes Overview

The following model elements have Visual Basic specific stereotypes:

Class Stereotypes

Method Stereotypes

Component Stereotypes


Stereotypes of Classes - VB

The stereotype of a class controls the Visual Basic code that Visual Modeler produces for the class. You define the stereotype value on the General tab in the Class Specification dialog box.

If the stereotype value is empty or unknown to the Visual Basic code generator (that is, not any of the values in the table below), Visual Modeler generates a class module for the class, and a module definition for a class utility. If you want a class to be generated into some other type of Visual Basic element, you have to change the class stereotype. Note that once you have generated a class Visual Basic will not let you alter its implementation type.

If the stereotype is set to “Control”, Visual Modeler does not generate any code for the class. However, all association relationships referring to such a class result in type or object variable declarations.

The following stereotypes of classes are used in Visual Modeler when generating or reverse engineering Visual Basic code.

Stereotype:	Meaning:

“Class Module”	(Default) Represents a class module in Visual Basic. Class modules can be both generated and reverse engineered by Visual Modeler.

“Control”	This value is used for classes that are not supposed to be generated. Thus, Visual Modeler does not generate a declaration for the class.

“Data Class”	Represents a data class in Visual Basic. Data classes can be reverse engineered, but not generated, by Visual Modeler

“Data Type”	Represents a fundamental data type, both default types and user defined types. Data types can be reverse engineering, but not generated.

“Enum”	Represents an enum declaration in Visual Basic. Enums can be reverse engineered from ActiveX components and type libraries, but not generated.

“Form”	Represents a form in Visual Basic. Forms can be reverse engineered, but not generated, by Visual Modeler

“Interface”	Represents a public interface class in Visual Basic. When reverse engineering a component, its interface classes is generated into the model as classes with the stereotype “Interface”. A class with the stereotype “Interface” is generated as a class module with the instancing property Public in the code.

“Module”	Represents a module in Visual Basic. Modules can be both generated and reverse engineered by Visual Modeler.

“MDIForm”	Represents an MDI form in Visual Basic. MDI forms can be reverse engineered, but not generated, by Visual Modeler

“PropertyPage”	Represents a property page in Visual Basic. Property pages can only be reverse engineered, but not generated, by Visual Modeler

“UserControl”	Represents a user control in Visual Basic. User controls can be reverse engineered, but not generated, by Visual Modeler

“UserDocument”	Represents a user document in Visual Basic. User documents can be reverse engineered, but not generated, by Visual Modeler

See Also

Classes and Visual Basic


Stereotypes of Methods - VB

The stereotype of a method controls the Visual Basic code that Visual Modeler produces for the method.

The stereotype can be used to declare a property Get, Let, or Set procedure, a reference to an external procedure in a dynamic-link library (DLL), or an event handler. If the stereotype is empty, Visual Modeler produces a sub, or a function declaration, depending on whether there is a result type declared for the method or not.

The following table summarizes the possible values for the method stereotype when generating or reverse engineering Visual Basic code. In this table, result is the return type of the member function, fname is the name of the member function, and params is the formal parameter list:

Stereotype:	Meaning:

no stereotype	(Default) Represents a sub or a function declaration, depending on the availability of a result type. For example:

Sub fname (params)

Function fname (params) As result

Sub and function declarations can be both generated and reverse engineered.

“Get”	Represents a property Get procedure, such as Public Property Get fname () As result. Property Get procedures can be both generated and reverse engineered.

“Let”	Represents a property Let procedure, such as Public Property Let fname (params). Property Let procedures can be both generated and reverse engineered.

“Set”	Represents a property Set procedure, such as Public Property Set fname (params). Property Set procedures can be both generated and reverse engineered.

“Declare”	Represents a reference to external procedures in a dynamic-link library, for example:

Declare Sub fname Lib libname (params)

Declare Function fname Lib libname (params)

As result

Declare declarations can be both generated and reverse engineered.

“Event”	Visual Modeler declares an event handler, such as Event fname (params). Events can be both generated and reverse engineered.

See Also

Methods and Visual Basic


Stereotypes of Components - VB

The stereotype and language of a component indicates to what kind of software module the component corresponds. To generate a Visual Basic project from a component, the language of the component must be set to “Visual Basic”, and the stereotype must be set to one of the values in the table below, except “ActiveX”.

The following component stereotypes can be used when generating or reverse engineering Visual Basic code:

Stereotype:	Meaning:

“DLL”	Represents a Visual Basic project of the type ActiveX DLL. ActiveX DLL projects can be both generated and reverse engineered.

“EXE”	Represents a Visual Basic project of the type Standard EXE. Standard EXE projects can be both generated and reverse engineered.

“ActiveX Control”	Represents a Visual Basic project of the type ActiveX Control. ActiveX Control projects can be both generated and reverse engineered.

“ActiveX EXE”	Represents a Visual Basic project of the type ActiveX EXE. ActiveX EXE projects can be both generated and reverse engineered.

“ActiveX”	Represents an ActiveX component (.exe, .ocx, .dll, or .tlb file) that has been reverse engineered into the model. Thus, a component with this stereotype corresponds to a software module, and not to a Visual Basic project.

Any other value	When generating code for a Visual Basic component with any other stereotype value, the code generator creates a Standard EXE project.

Note that Visual Modeler understands all the component stereotypes above, even though some of them may not be available by default in the Stereotype field of the Component Specification dialog box.

See Also

Components and Visual Basic