Share via


Visual Basic Concepts

Working with Resource Files

A resource file allows you to collect all of the version-specific text and bitmaps for an application in one place. This can include icons, screen text, and other material that may change between localized versions or between revisions or specific configurations.

Adding Resources to a Project

You can create a resource file using the Resource Editor add-in. The compiled resource file will have a .res file name extension. Each project can contain only one resource file.

The actual file consists of a series of individual strings, bitmaps, or other items, each of which has a unique identifier. The identifier is either a Long or a String, depending on the type of data represented by the resource. Strings, for example, have a Long identifier, while bitmaps have a Long or String identifier. To retrieve resources in your code, learn the identifier for each resource. The function parameters referring to the resources can use the Variant data type.

To add a new resource file to your project

  1. Choose Resource Editor from the Tools menu. An empty resource file will be opened in the Resource Editor window.

    Note   The Resource Editor add-in must be installed. For information on installing add-ins, see "Using Wizards and Add-Ins" in "Managing Projects".

  2. Select the Save button on the Resource Editor toolbar to save the resource file. The file will be added to the Project Explorer under the Related Documents section.

To add an existing resource file to your project

  • Choose Add New Resource File from the Project menu. Any existing resource file in your project will be replaced.

    Caution   If you make any modifications to an existing resource file it could affect other projects that use that resource file. Make sure that you save the file under a new filename.

    Note   The Resource Editor add-in must be installed. For information on installing add-ins, see "Using Wizards and Add-Ins" in "Managing Projects."

For More Information   For more information on resource files, see "Using Resource Files for Localization" in "International Issues."

Note   Windows resource files are specific to 16-bit or 32-bit applications. Visual Basic will generate an error message if you try to add a 16-bit resource file to a project.

Using Resources in Code

Visual Basic provides three functions for retrieving data from the resource file for use in code.

Function Description
LoadResString Returns a text string.
LoadResPicture Returns a Picture object, such as a bitmap, icon, or cursor.
LoadResData Returns a Byte array. This is used for .wav files, for example.

For More Information   See the appropriate function topic.