Learn the Visual Basic Language (How Do I in Visual Basic)
This page links to help on widely used Visual Basic programming tasks. To view other categories of popular tasks covered in Help, see How Do I in Visual Basic.
In General
What's New in Visual Basic
Lists the new and enhanced features available with this release of Visual Basic.Language Changes for Visual Basic 6.0 Users
Provides a list of changes, with links to details, about how the Visual Basic language has changed since Visual Basic 6.0.
Object-Oriented Programming with Visual Basic
When to Use Inheritance
Discusses when to use inheritance instead of interfaces.Inheritance Basics
Covers inheritance modifiers, overriding methods and properties, MyClass, and MyBase.How to: Define an Operator
Shows how to define the behavior of a standard operator (such as *, <>, or And) when one or both of the operands is of the type of your class or structure.How to: Access Members of an Object
Explains how to read, write, or call a member of an object that you have created.How to: Define Multiple Versions of a Procedure
Explains how to define a procedure in multiple versions by overloading it, using the same name but a different parameter list for each version.
Work with Properties
How to: Put a Value in a Property
Demonstrates how to store a value in a property.How to: Get a Value from a Property
Demonstrates how to retrieve the value stored in a property.How to: Declare and Call a Default Property in Visual Basic
Demonstrates how to declare and call a property that can be accessed without using its name.How to: Declare a Property with Mixed Access Levels
Demonstrates declaring properties with different access levels for storing and retrieving.How to: Create a Property
Demonstrates how to create a property.
Use Inheritance
How to: Define a Class That Uses Members of an Existing Class.
Shows example code for creating a class that derives from another class.How to: Hide an Inherited Variable
Demonstrates using the Shadows keyword to hide an inherited variable.How to: Access a Variable Hidden by a Derived Class
Demonstrates how to access a base class variable that is hidden in a derived class.
Work with Procedures
How to: Create a Procedure
Explains how to declare a procedure to perform a task that is needed in several places in your code.How to: Call a Procedure that Returns a Value
Shows two ways to call a Function procedure and use the value it returns.How to: Call a Procedure that Does Not Return a Value
Discusses how to call a Sub procedure, which performs a task but does not return a value to the calling code.How to: Define a Parameter for a Procedure
Covers defining a parameter list to accept values passed to the procedure by the calling code.How to: Pass Arguments to a Procedure
Demonstrates how to pass a value to a procedure by supplying an argument for each of its parameters.
Manage Program Control Flow
How to: Break Large Pieces of Code into Smaller Pieces.
Explains how to use procedures to achieve structured programming in your codeHow to: Break and Combine Statements in Code
Covers breaking a single statement into several source code lines and combining several statements onto one source line.How to: Add a Comment to Your Code (Visual Basic)
Shows two ways to place explanatory comments in your source code.
Conditional Statements
- How to: Run Statements Depending on One or More Conditions
Demonstrates using If...Then...Else constructions to run different blocks of statements depending on various conditions.
Functions and Subroutines
How to: Create a Procedure
Explains how to declare a procedure to perform a task that is needed in several places in your code.How to: Call a Procedure that Returns a Value
Shows two ways to call a Function procedure and use the value it returns.How to: Call a Procedure that Does Not Return a Value
Discusses how to call a Sub procedure, which performs a task but does not return a value to the calling code.How to: Define a Parameter for a Procedure
Covers defining a parameter list to accept values passed to the procedure by the calling code.How to: Pass Arguments to a Procedure
Demonstrates how to pass a value to a procedure by supplying an argument for each of its parameters.
Loop Statements
How to: Skip to the Next Iteration of a Loop
Explains how to skip out of the current iteration of a loop and proceed to the next iteration.How to: Run Several Statements Repeatedly
Shows how to run a block of statements either a set number of times or until a condition is met.How to: Iterate through a Collection in Visual Basic
Demonstrates a For Each...Next loop, which runs the same statements for each element of a collection.How to: Improve the Performance of a Loop
Covers choosing the most efficient data type for the control variable of a loop.
Work with Collections, Generics, and Arrays
How to: Define Collections in Your Classes
Demonstrates defining and using a simple Visual Basic Collection object.Managing Your Objects with Collections
Discusses criteria to consider when choosing the type of collection for grouping related objects.How to: Add, Delete, and Retrieve Items of a Collection
Describes the fundamental operations of adding a new element, removing an existing element, and retrieving an element.How to: Create a Collection of Objects
Covers Visual Basic collections and generic collections, how to create them, and how to iterate through them.
Collections
How to: Create an Array of Objects
Explains arrays as an alternate way to group related objects together.Troubleshooting Collections
Lists common problems encountered with collections and shows how to deal with them.
Generics
How to: Use a Generic Class
Demonstrates how to use a class that takes one or more type parameters.How to: Pass an Array to a Procedure or Property
Discusses how to pass an array of values to a procedure or property using the argument list.How to: Define a Class That Can Provide Identical Functionality on Different Data Types
Shows how to define a single class that adapts to different data types to perform the same functionality.
Arrays
How to: Create an Array
Shows two ways to create an array object and assign it to an array variable.How to: Initialize an Array Variable
Explains how to store an array in an array variable, and how to set its length and element values.How to: Initialize a Jagged Array
Shows four ways to store an array of arrays, or jagged array, in a variable, and how to set its length and element values.How to: Initialize a Multidimensional Array
Shows four ways to store an array of more than one dimension in a variable, and how to set its length and element values.How to: Put a Value into an Array
Describes how to store a value in an array element.How to: Sort An Array in Visual Basic
Explains how to sort the elements of an array alphabetically.How to: Reverse the Contents of An Array in Visual Basic
Demonstrates how to reverse the order of the elements of an array.How to: Specify a Zero Lower Bound on an Array
Discusses making your code easier to read by declaring the lower bound of an array as zero.
Work with Variables
How to: Create a New Variable
Covers the Dim statement and the various keywords and clauses you can use to create a variable.How to: Create an Object
Discusses object variables and how to create an instance of a class.How to: Move Data Into and Out of a Variable
Describes how to store and retrieve the value of a variable.
Declare and Initialize Variables
How to: Declare an Object Variable and Assign an Object to It in Visual Basic
Explains the Object data type and how to assign an object of any type to it.How to: Hold More Than One Value in a Variable
Discusses composite data types such as structures, arrays, and classes, which can hold multiple values.How to: Hold True and False Values in a Variable
Discusses the Boolean data type and how to declare variables to hold logical values.How to: Lengthen a Variable's Lifetime
Describes the Static keyword and how to use it to make a variable exist after its containing element ceases to exist.How to: Determine Whether Two Objects Are Related
Demonstrates using the GetType method to find out if one object inherits from another.
Control Variable Scope
How to: Control the Scope of a Variable
Discusses the levels of scope and how to use them to control what code can make a reference to a variable.How to: Control the Availability of a Variable
Explains the different access levels and how to assign one to a variable to control what code can read or write it.How to: Hide a Variable with the Same Name as Your Variable
Shows two ways to use shadowing to hide a variable with another one of the same name.
Interact with Data Types
- Data Types in Visual Basic
Describes how to assign a data type to various kinds of programming elements.
Characters and Strings
How to: Hold Characters in a Variable
Discusses the Char and String data types and how to declare variables to hold character values.How to: Match a String against a Pattern
Shows how to use the Like operator to match a character in a string against a variety of character sets.How to: Remove Parts of a String (Visual Basic)
Demonstrates how to remove all occurrences of a substring from a string.
Numeric Values
How to: Hold Integers in a Variable
Discusses the SByte, Short, Integer, and Long data types and how to declare variables to hold signed integer values.How to: Hold the Most Significant Digits in a Variable
Discusses the Decimal data type and how to declare variables to hold up to 29 significant digits.How to: Hold the Largest Possible Number in a Variable
Discusses the ULong, Decimal, Single, and Double data types and how to declare variables to hold very large values.How to: Hold Fractions in a Variable
Discusses the Single and Double data types and how to declare variables to hold fractional values.
Convert Data Types
- How to: Convert an Object to Another Type in Visual Basic
Covers type conversions from the Object data type to a more specific data type.
Date and Time
- How to: Hold Date and Time Values in a Variable
Discusses the Date data type and how to declare variables to hold date and time values.
Unsigned Types
How to: Optimize Storage of Positive Integers With Unsigned Types
Discusses the UInteger data type and how to declare variables to hold positive integer values with optimum efficiency.How to: Call a Windows Function that Takes Unsigned Types
Discusses the Byte, UShort, UInteger, and ULong data types and how to interface with functions that use unsigned types.
Currency
- How to: Hold Money Values in a Variable.
Discusses the Decimal data type and how to declare variables to hold monetary values.
Program using Events
How to: Call an Event Handler in Visual Basic
Demonstrates how to define an event and an event handler, and uses the AddHandler statement to associate them.How to: Create Event Handlers in the Visual Basic Code Editor
Gives directions for using the Visual Basic Code Editor to write code to respond to events.How to: Raise an Event (Visual Basic)
Demonstrates how to define an event and uses the RaiseEvent statement to cause the event to occur.Walkthrough: Declaring and Raising Events
Steps through the process of declaring and raising events for a class.Walkthrough: Handling Events
Demonstrates how to write an event handler procedure.
Handle Errors and Exceptions
How to: Retrieve Information from an Error Object
Demonstrates how to get information from the Err object's properties.How to: Retain Control When an Error Occurs
Shows how to run a particular block of statements if a specified exception occurs while your code is running.Walkthrough: Structured Exception Handling
Provides a walkthrough of creating a simple application and inserting exception handling code.How to: Test Code with a Try…Catch Block in Visual Basic
Demonstrates how to use a Try...Catch block to test a section of code.
Samples
- Visual Basic Language Samples
These samples demonstrate Visual Basic language concepts.