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 of a UserForm or module.

tmp757e-143_thumb

Notice how the declaration starts with Type and finishes with End Type, and that every element within the declaration has its type explicitly defined. These types need to be specified so that the interpreter can calculate the amount of memory required by a new type, by summing the memory requirements of each element. User-defined types can include other user-defined types, provided that they have been previously declared so that Visual Basic can do its memory calculations.

The benefits of having a user-defined type is that related items of data are grouped together in one named variable that can be passed as a procedure argument, rather than your having to pass each item individually. The scope rules that apply to constants and variables also apply to types. See the section “Scope of Constants and Variables” earlier in this topic.

Next post:

Previous post: