For our purposes we will be interested in two parts of the extensibility object. The most important is the VBIDE object, which contains everything we need to fully manipulate the Visual Basic IDE. The VBIDE main object is the Visual Basic Editor or VBE. The VBE has many objects with many properties and methods. We will only look at a few of the properties and methods. First, let us consider what we want to do. To generate a project we will need to do the following:
> We will make an ActiveX control project for each table in the database. We will therefore need to add a new project to the group for each table.
> As we will discuss in more detail below, each project will consist of two classes, the control and a . bas module. Therefore, we will need the ability to add modules to our Visual Basic projects.
> We will need to add references to our project.
> We will need to change the names of the project and the parts of the project.
The VBE object hierarchy looks as follows:
We have included the methods that we will be using with the objects.
You can see that the VBE object is the main managing object of the Visual Basic IDE. The VBProjects object manages VBProject objects, the References object manages Reference objects and the VBComponents object manages VBComponent objects. As you can see, this object hierarchy is built just like the business services components we discussed in Chapter 8, except that this hierarchy is a little more complex and it has more objects and levels. If you look at the managing classes in the Visual Basic object browser, you will see that they consist primarily of methods. The managed classes are primarily properties.
The methods that we will need to use are:
> The Add method of the VBProjects object, which will return a new VBProject object.
> The AddFromGUID method of the References object, which will add a new reference object to the project object based on the GUID of the reference.
> The Item method of the VBComponents object which will return one of the project's components, such as a class or a form.
> The AddFromString method of the CodeModule object that allows you to use a string to add code to a module.
Now let us take a look at the CodeGenerator project that we will use to create this project.
Was this article helpful?