Visual Basic

A program is simply a series of instructions that tell the computer what to do. Although programs can be complex, each individual instruction is generally simple. The computer starts at the beginning and works through, line by line, until it gets to the end. Here are some of the essential elements in Visual Basic:

Don't-Forget-New
The Visual Basic IDE is a safe environment in which to experiment and learn from your mistakes.

Statements
A statement is an instruction that performs an action. For example, the statement Lbl.BackColor = Color.Blue sets the background color of Lbl to Blue.

Functions
A function is a statement that returns a value. For example, the function InputBox() returns the value of its dialog text field.

Variables
A variable is a word defined in the program that stores a value. For example, the statement msg = “Hello World!” stores a string of characters in a variable called msg.

Operators
An operator is an arithmetical symbol. For example, the * asterisk character is the multiplication operator and the / forward slash character is the division operator.

Objects
An object is a program “building block” entity. It can be visible, like a Button control, or invisible like a Timer control.

Properties
A property is a characteristic of an object. For example, the property Btn.Text is the Text property of the Btn object.

Methods
A method is an action that an object can perform. For example, the method Btn.Click() is the Click method of the Btn object.

Comments
A comment is an explanatory line in the program code starting with an apostrophe ’ character. It’s not actually read by the compiler but exists to explain the purpose of the code. For example, ‘ Clear the list. might explain a Clear statement.

 

The illustration below shows the Code Editor view of Visual Basic programming code, for the Click event-handler of a Button control – line numbering is turned on to aid analysis of the code.

 

Line-by-line analysis

Syntax highlighting

 

Hot-Tip-New_cropped
To turn on line numbering, click on Tools, Options, then expand Text Editor, Basic. Choose General then check the Line Numbers option.

 

 

Beware-New

 

The syntax colors shown here are the default colors. Custom colors can be chosen in the Tools, Options dialog, by expanding Environment, Fonts and Colors.

 

 

 

 

Visual Basic in easy steps, 4th Edition 9781840787016

Want to know more?

For the complete Visual Basic guide covering Visual Studio Community 2015, all in the trusted In Easy Steps style, click here. In full-colour and straightforward, jargon-free language, Visual Basic in easy steps, 4th edition shows you how to quickly create Windows applications using the latest free programming environment. This book gives you code examples, screenshots, and step-by-step instructions that illustrate each aspect of Visual Basic.

See also: Generating a random number in Visual Basic

We are sorry to let you go...

Would you mind giving us your feedback or reason of cancelling the subscription?

 

"*" indicates required fields

Hidden
Hidden
Hidden
Reason For Cancellation*
Hidden