Learn the most popular programming language of the most popular Operating System: Windows

Ad

Visual Basic Statements and Instructions

The discussion of objects and encapsulation in "Forms and Controls", uses several lines of Visual Basic code, including examples of object properties being assigned values and methods being invoked.  The terms code and instructions can be used interchangeably, but the term statement means something specific in Visual Basic.

Visual Basic Statements

A statement differs from the assignment of a property or invocation of a method.  Consider the following definition: A statement is a reserved word that causes a computer program or the operating system to do something.  Statements are instruction (code) that are built in to the Visual Basic language.  Methods are code held by an object.

If you look at the Visual Basic Help, you discover that some keywords are statements.  for example, the keyword End is a statement that ends (stops) the execution of a Visual Basic program.  The keyword Kill (sorry, this is in the language) is a statement that deletes a file from a disk.

As another example, the statement to force explicit declaration of all variables is written as follows:

Option Explicit

In this example, no reference to an object is required because the statement is built into the language.

Visual Basic Program Instructions

Methods, statements and Visual Basic instructions are different.  An instruction is simply a line of code in a Visual Basic application.  Instructions contain the names of constants, variables, functions, properties, methods and built-in Visual Basic statements.  The rule to remember regarding instructions is that all instructions begin with a statement or the invocation of an object method.

  For example, an instruction beginning with a statement is as follows:

End

The following is an instruction beginning with a method:

List1.AddItem Entry

The method is AddItem and the object is List1.

Finally, some instructions beginning with methods or statements also contain what are known as statement or method arguments.  Consider the following:

Form1.Move Left + (width \ 10), Top + (Height \ 10)

In this instruction, Move is a method and Left, width, Top and Height are properties of the object, Form1 that are used as method arguments.  An example of a built-in Visual Basic statement that takes an argument is the AppActivate statement:

AppActivate “Calculator”

In this case, the statement shifts focus to a running instance of the Calculator utility bundled with Windows.

This all may seem a bit confusing right now, but you will get used to working with objects, methods and statements once you begin writing Visual Basic programs.

Technorati Tags: ,
Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Featured Post

Coded Statements and Methods

In the preceding procedure , you wrote several coded instructions, which introduced two different programming statements and a method: the D...

Recent Posts