AutoCAD VBA

Scope of Constants and Variables (VBA Programming Concepts) (AutoCAD VBA)

The scope of a constant or variable refers to whether or not it can be accessed from one procedure, from all procedures in a module, or from all procedures in the application. The level of scope depends on where the element has been declared and whether it has been declared as public or private. Variables […]

Defining Your Own Types (VBA Programming Concepts) (AutoCAD VBA)

You may want to combine a few related items of data together into new types. These are called user-defined types. For example, suppose you want to create a type named LineDetails that combines all the details about a line. All you need to do is place the following type definition into the General Declarations section […]

Using Conditions to Control Code Execution (VBA Programming Concepts) (AutoCAD VBA)

If statements allow you to set conditions that determine whether or not a block of code gets executed. You have just seen the If statement in action in Listing 4.1. VBA offers a variety of If statement structures, which are all described in this section. Also included here is the Select Case statement, which allows […]

Using Loops to Repeat Code (VBA Programming Concepts) (AutoCAD VBA)

This section shows you how to execute a block of code repeatedly, for a specified number of times using the For loop, or until a certain condition arises using the While loop. You’ll find these two loops used in many of the coding exercises throughout this topic. The For loop is especially useful when all […]

Repeating Code an Unknown Number of Times (VBA Programming Concepts) (AutoCAD VBA)

When you want to repeat a block of code while some condition evaluates to True (or False), but you don’t know the number of times required, you need to include a While loop. The structure of the While loop is as follows: One of the most common uses of the While loop is to read […]

Overview of Objects, Properties, Methods, and Events (VBA Programming Concepts) (AutoCAD VBA) Part 1

VBA is an object-oriented environment, containing many different classes of objects. Each class has its own set of properties to define the appearance of the objects, and methods to manipulate the objects that are instances of that class. Some classes, such as Toolbox controls, also have their own set of event procedures that are coded […]

Overview of Objects, Properties, Methods, and Events (VBA Programming Concepts) (AutoCAD VBA) Part 2

All about Properties Each class of object has its own set of properties. These properties are initially set to default values when the object they belong to is first created. Properties define how an object appears on the screen, including things such as coloring, dimensions, and position—there is even a Visible property that can be […]

Overview of Objects, Properties, Methods, and Events (VBA Programming Concepts) (AutoCAD VBA) Part 3

All about Methods A method is a procedure that performs some action on the object with which it is associated. Some examples of methods that belong to the AutoCAD drawing object are AddText, AddLine, GetAngle, and Rotate. When called, some methods have parameters to which you assign values by listing arguments in the same order […]

Comparing VBA Programming Constructs (VBA Programming Concepts) (AutoCAD VBA)

This section describes what is meant by each of the terms macro, procedure, function, program, and application, including the relationships and differences that exist among them. Macros A macro is a set of instructions that is executed each time its name or associated shortcut key is used. Macros can be one-liners or they can be […]

Setting the Tab Order for Controls (VBA Programming Concepts) (AutoCAD VBA)

When your application is running, you can tab from text box to text box. The tab order is the same as the order in which you added the controls. This section describes how you can change this order—especially if you want to add more controls as an afterthought. If you have ever had a broken […]