Tutorial for Visual Basic Commands

by Leon Williams

Visual Basic, like any other programming language, employs special keywords known as commands. Unlike variables, which are named and defined within your code, command names are defined by the Visual Basic language itself and cannot be changed.

What Are Visual Basic Commands?

The difference between a variable and a command in programming is similar to the difference between a noun and a verb in the English language. A variable holds data, but a command evaluates or manipulates that data. Differences in the names and use of different commands are essentially what make one programming language different from another. As a programmer, you may be able to accomplish the same task coding in either C++ or Visual Basic, but the code involved would be drastically different between the two projects because of the way each language defines and interprets commands. In Visual Basic programming, the most basic commands---ones that you will use over and over in your projects---can be put into three categories: declarations, operators/math, and loops.

Essential Visual Basic Commands by Category

DECLARATIONS Programming languages use commands called "declarations" to define and populate variables. Declarations can be a stumbling point for Visual Basic beginners because much of the syntax used is unique to Visual Basic. "Dim" (and "As") is used to declare a variable. Examples: "dim MyString as string" or "n = dim n as integer." "Static" is similar to what might be called a "global" in other languages; a "static" variable does not lose its assigned value until the entire program has been terminated. (I.e., it does not lose its value every time the particular procedure is ended.) "Public" defines a variable that can be used externally (i.e., by procedures other than the one in which it is created). OPERATORS AND MATH Basic math functionality falls under the "operators" category. Mathematical symbols such as "+", "-", "/" and "*" serve their usual purpose. Comparative operators such as "and" and "or" are also used the same as you'd see them in other languages. Other Visual Basic commands categorized as operators: "Eqv" performs a comparison against two logical variables. The command "Output = YesNoA eqv YesNoB" will set the variable Output "true" if both YesNoA and YesNoB are true. "Like" compares a string against a pattern. The command "Output = MyString like MyPattern" will return a "true" value to Output if MyString adheres to the pattern defined by MyPattern. LOOPS The basic use of loops and conditional arguments in Visual Basic programming is largely identical to other modern programming languages. The familiar "if/then/else," "while" and "for each/next" arguments are all available for use in Visual Basic programming. "Wend" is used as an "end" command for a "while" loop in Visual Basic. Programmers familiar with languages where a "while" loop uses "end," or languages limited to closing a "while" loop using parenthetical-type containers, will want to take note of the "wend" command.

Other Visual Basic Commands

These three categories are by no means an exhaustive reference for Visual Basic commands. There are hundreds more. One benefit of Visual Basic is the prevalence of predefined commands for advanced mathematical concepts and operating system interaction. Many processes that you would have to create "by hand" in other languages are available in Visual Basic as pre-existing commands, especially when it comes to things such as parsing and comparing files, or creating and manipulating Windows elements.

About the Author

Leon Williams has worked as a fiction editor, sporting goods retailer, rock musician, systems analyst, help desk technician and marketing coordinator. He holds a bachelor's degree from Northern Michigan University, where he studied English, computer science and new media. He has had work published in a variety of online venues as well as the Uncle John's Bathroom Reader series of books.