Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
George Omura. Lisp programing tutorial for AutoCAD customization / Using VBA to Create AutoCAD Applications - Omura, George.pdf
Скачиваний:
116
Добавлен:
02.05.2014
Размер:
883.43 Кб
Скачать

Using VBA to Create AutoCAD Applications

Chapter 99

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

In the previous chapter, you learned the basic syntax of VBA, and you’ve already been introduced to the AutoCAD object model (see Chapter 98 on this CD for a review). Now it’s time

to put these pieces together with some additional concepts to create an actual AutoCAD application. In this chapter, you’ll learn about UserForms, which provide a set of user interface tools for applications written in VBA. You’ll see how to call a UserForm from the AutoCAD interface, how to have the UserForm do useful work, and how to make your AutoCAD VBA code resident when the user first starts AutoCAD. Along the way you’ll also explore the VBA editor a bit further.

Using UserForms

Adding and Manipulating Controls

Types of Controls

Naming Controls

UserForm Events

Working with Forms in AutoCAD

What’s Going On? Debugging Support

If You Want to Experiment…

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

USING VBA TO CREATE AUTOCAD APPLICATIONS

3

Shortcuts

To Create a New UserForm

Select Insert UserForm from the VBE menu.

To Add a Control to a UserForm

Select the control in the Controls toolbox, then click the mouse on the UserForm.

To Set Properties of Controls

Type new values for the properties into the Properties Window.

To Display Static Text and Pictures on a UserForm

Use a Label or Image control.

To Display Editable Text on a UserForm

Use a TextBox control.

To Allow Selection from a List of Items on a UserForm

Use a ListBox or ComboBox control.

To Choose between Two Values on a UserForm

Use a CheckBox, OptionButton, or ToggleButton control.

To Start Code from a UserForm

Use a CommandButton control.

To Run Code in Response to User Actions

Write event procedures in the UserForm’s module.

To See the List of Events, Properties, or Methods for a Control

Use F2 to open the Object Browser.

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

4

CHAPTER NINETY-NINE • USING VBA TO CREATE AUTOCAD APPLICATIONS

To Analyze Code While It Runs

Set a breakpoint by clicking the code’s margin bar, and then use F8 to single-step through the code.

To View the Values of Variables in Code

Use the Locals Window.

Using UserForms

In addition to the VBA language and the VBA editor, VBA includes a user interface component. This is the Microsoft Forms 2 package, which is included with all VBA host programs. In this section, you’ll learn to use Forms 2 to create dialog boxes. These dialog boxes can launch VBA code and serve as a way to tie your procedures to your AutoCAD applications.

Apparently, there never was a Microsoft Forms 1. Microsoft Forms 2 was the first version to actually be released, which means you won’t have to worry about upgrading from older versions of Forms.

Creating UserForms

To create a new UserForm, select Insert UserForm from the VBE menu. This creates a new form, opens it in design mode, and displays the Controls toolbox, as shown in the right side of Figure 99.1.

Design mode is one of the two modes that UserForms can be in. This is the mode that allows you to develop the UserForm. When a form is displayed in the AutoCAD interface, it’s said to be in Run mode.

The blank UserForm is an empty palette that you can use to design a dialog box. To make the UserForm more useful, you need to add controls from the toolbox. You’ll learn how to do that in the next section.

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com