Partilhar via


Visual Basic Concepts

Experimenting With the Extensibility Model

Once you become more familiar with the extensibility model, it can help to experiment with the various properties, methods and events contained in it. The following is one way to do this:

  1. Start Visual Basic and choose Addin as the project type in the New Project dialog.

  2. In the Visual Basic Project Explorer, right click the Connect designer and select View Code.

  3. Use Find from the Edit menu to search for OnConnection. This should place the cursor in the IDTExtensibility_OnConnection procedure.

  4. There is a comment 3 or 4 lines into the procedure suggesting that the following statement is a good place to put a breakpoint for testing code. Place a breakpoint on the suggested line.

  5. Place your cursor in the Immediate window, type AddToIni, then press Enter to execute that procedure. (AddToIni is a procedure in the module Addin.Bas.) Alternately, you can also register add-ins using the Add-In Designer. To do this, double-click the Connect designer and fill out the required information. For more information on this, see "Creating a reference with the Add-In designer" in .

  6. Press F5 to put the Addin into Run mode.

  7. Start another instance of Visual Basic. Choose the default (Standard Exe) from the initial dialog, then choose Add-In Manager from the Add-Ins menu.

  8. In the Add-In Manager dialog, select My Addin-In in the list of Available Add-Ins, check Loaded/Unloaded in the Load Behavior box, then click OK. The IDTExtensibility_OnConnection event is called in the first instance of Visual Basic, and execution is suspended at the breakpoint that you set in step #4.

  9. Use Step Into from the debug menu to execute the line:

    Debug.Print VBInst.FullName
    

    Notice that the path and name of the current instance of Visual Basic is printed in the Immediate window.

  10. You can now use VBInst as the object for the example code. Simply replace the dummy object Application.VBE with the Visual Basic object VBInst before executing the example lines in the Immediate window.

For example, you can modify the example:

 Print Application.VBE.VBProjects(1).VBComponents.Count

to read as follows:

 Print VBInst.VBProjects(1).VBComponents.Count

When you press Enter on the latter line in the Immediate window, the   number of Visual Basic components is printed on the next line.

You now can experiment with various methods and properties in the Immediate window.