Programming 11/12: Visual Basic Terminology

Program Statement: A line of code in a Visual Basic program; a self contained instruction executed by the Visual Basic compiler that performs useful work within the application. Program statements can vary in length (some contain only one Visual Basic keyword!), but all program statements must follow syntax rules defined and enforced by the Visual Basic compiler. In Visual Studio 2010, program statements can be composed of keywords, properties, object names, variables, numbers, special symbols, and other values.

Keyword: A reserved word within the Visual Basic language that is recognized by the Visual Basic compiler and performs useful work. (For example, the End keyword stops program execution.) Keywords are one of the basic building blocks of program statements; they work with objects, properties, variables, and other values to form complete lines of code and (therefore) instructions for the compiler and operating system. Most keywords are shown in blue type in the Code Editor.

Variable: A special container used to hold data temporarily in a program. The programmer creates variables by using the Dim statement and then uses these variables to store the results of a calculation, file names, input, and other items. Numbers, names, and property values can be stored in variables.

Control: A tool that you use to create objects in a Visual Basic program (most commonly, on a form). You select controls from the Toolbox and use them to draw objects with the mouse on a form. You use most controls to create UI elements such as buttons, picture boxes, and list boxes.

Object: An element that you create in a Visual Basic program with a control in the Toolbox. (In addition, objects are sometimes supplied by other system components, and many of these objects contain data.) In Visual Basic, the form itself is also an object. Technically speaking, objects are instances of a class that supports properties, methods, and events. In addition, objects have what is known as inherent functionality—they know how to operate and can respond to certain situations on their own. For example, a list box “knows” how to scroll.

Class: A blueprint or template for one or more objects that defines what the object does. Accordingly, a class defines what an object can do, but it is not the object itself. In Visual Basic, you can use existing .NET Framework classes (like System.Math and System.Windows.Forms.Form), and you can build your own classes and inherit properties, methods, and events from them. (Inheritance allows one class to acquire the pre-existing interface and behavior characteristics of another class.) Although classes might sound esoteric at this point, they are a key feature of Visual Studio 2010. In this book, you will use them to build user interfaces rapidly and to extend the work that you do to other programming projects.

Namespace: A hierarchical library of classes organized under a unique name, such as System.Windows or System.Diagnostics. To access the classes and underlying objects within a namespace, you place an Imports statement at the top of your program code. Every project in Visual Studio also has a root namespace, which is set using the project’s Properties page. Namespaces are often referred to as class libraries in Visual Studio books and documentation.

Property: A value or characteristic held by an object. For example, a button object has a Text property, to specify the text that appears on the button, and an Image property, to specify the path to an image file that should appear on the button face. In Visual Basic, properties can be set at design time by using the Properties window, or at run time by using statements in the program code. In code, the format for setting a property is

Object.Property = Value

where Object is the name of the object you’re customizing, Property is the characteristic you want to change, and Value is the new property setting. For example,

Button1.Text = "Hello"

could be used in the program code to set the Text property of the Button1 object to “Hello”.

Event Procedure: A block of code that’s executed when an object is manipulated in a program. For example, when the Button1 object is clicked, the Button1_Click event procedure is executed. Event procedures typically evaluate and set properties and use other program statements to perform the work of the program.

Method: A special statement that performs an action or a service for a particular object in a program. In program code, the notation for using a method is Object.Method(Value) where Object is the name of the object you want to work with, Method is the action you want to perform, and Value is zero or more arguments to be used by the method. For example, the statement ListBox1.Items.Add("Check") uses the Add method to put the word Check in the ListBox1 list box. Methods and properties are often identified by their position in a collection or class library, so don’t be surprised if you see long references such as System.Drawing.Image.FromFile, which would be read as “the FromFile method, which is a member of the Image class, which is a member of the System.Drawing namespace.

Reference

Halvorson, M. (2010). Chapter 3 Working with Toolbox Controls. Microsoft Visual Basic 2010 step by step (pp. 89-91). Redmond, WA: Microsoft Press.