1. Technology

How To Use Resources in Visual Basic 6

What's a "resource" ???


After Visual Basic students learn all about loops and conditional statements and subroutines and so forth, one of the next things that they often ask about is, "How do I add a bitmap, a wav file, a custom cursor or some other special effect?" One answer is resource files. When you add a file using Visual Studio resource files, they're integrated directly into your Visual Basic project for maximum execution speed and minimum hassle packaging and deploying your application.

Resource files are available in both VB 6 and VB.NET, but the way they're used, like everything else, is quite a bit different between the two systems. This article is part one of a two part series about resource files. This first article is about how to use them in VB 6 and the next article covers VB.NET.

Keep in mind that this isn't the only way to use files in a VB project, but it has real advantages. For example, you could include a bitmap in a PictureBox control or use the mciSendString Win32 API. "MCI" is a prefix that usually indicates a Multimedia Command String. (For more information about MCI API calls, consult this page at Microsoft.)

Creating a Resource File in VB 6

You can see the resources in a project in both VB 6 and VB.NET in the Project Explorer window (Solution Explorer in VB.NET - they had to make it just a little bit different). A new project won't have any since resources aren't a default tool in VB 6. So let's add a simple resource to a project and see how that is done.

Step one is to start VB 6 by selecting a Standard EXE project on the New tab in the startup dialog. Now select the Add-Ins option on the menu bar, and then the Add-In Manager.... This will open the Add-In Manager dialog window.

Scroll down the list and find VB 6 Resource Editor. You can just double-click it or you can put a check mark in the Loaded/Unloaded box to add this tool to your VB 6 environment. If you think you're going to use the Resource Editor a lot, then you can also place a check mark in the box Load on Startup and you won't have to go through this step again in the future. Click "OK" and the Resources Editor pops open. You're ready to start adding resources to your project!

Go to the menu bar and select Project then Add New Resource File or just right-click in the Resource Editor and select "Open" from the context menu that pops up. A window will open, prompting you for the name and location of a resource file. The default location will probably not be what you want, so navigate to your project folder and enter the name of your new resource file into the File name box. In this article, I'll use the name "AboutVB.RES" for this file. You'll have to confirm the creation of the file in a verification window, and the a "AboutVB.RES" file will be created and filled into the Resource Editor.

  1. About.com
  2. Technology
  3. Visual Basic

©2014 About.com. All rights reserved.