How Code Instructs the Computer (VBA Programming Concepts) (AutoCAD VBA)

This topic explains the coding concepts and terminology of VBA. If you have previous experience in writing code, some of the material will be familiar to you, so you may want to make your first read a quick one. But I’m sure you’ll find it a continuing handy reference as you gain experience. And for you uninitiated, the topic provides invaluable instruction.

The Visual Basic compiler partially translates each line of code into p-code whenever you press Enter. It provides instant feedback when it discovers any obvious errors. This translated version of code is saved so that when you run your project, the compiler doesn’t have to start from scratch, which saves time.

Using traditional compiled languages, you develop all the code before compiling it into machine language instructions for the PC to execute. Using Visual Basic, there are no longer two distinct steps because some compilation goes on in the background as you develop your code. Before beginning the final compilation step, most syntax errors will have been corrected, and the code will already be in a form that’s part of the way there. It just has to undergo the finishing touches in order to become the machine-language instructions your PC can execute.

Statements and Expressions

All the code you write is made up of statements that may or may not contain expressions. Be sure you understand the difference between a statement and an expression. When the interpreter is translating a statement, any expression contained in the statement is reduced to a value before continuing.

Statements Any line of code in a VBA application is called a program statement. Because statements are partially compiled into p-code, they must be in a form that can be translated by the compiler program. Program statements can contain a mixture of keywords; names that identify variables; objects and their properties and methods; functions, macros, and procedures.. .and more. You’ll find all these terms defined later in this topic.

Expressions An expression is any combination of values and symbols that can be reduced to a single value. For example, the statement


contains an expression on the right of the equals sign (=). A value is retrieved from the TextBox control’s Text property and multiplied by the conversion factor, to reduce the right-hand side of the equation to a single numerical value. This value is then assigned to the text box on the left-hand side.


False is an expression that evaluates to a single numerical value representing False.

Next post:

Previous post: