| You are here: | About>Computing & Technology>Visual Basic> Use VB 6> How To Use Resources in Visual Basic 6 |
![]() | Visual Basic |
How To Use Resources in Visual BasicLoading Resources in VB 6VB6 supports
VB 6 provides a simple editor for strings but you have to have a file created in another tool for all of the other choices. For example, you could create a BMP file using the simple Windows Paint program. Each resource in the resource file is identified to VB 6 by an Id and a name in the Resource Editor. To make a resource available to your program, you add them in the Resource Editor and then use the Id and the resource "Type" to point to them in your program. Let's add four icons to the resource file and use them in the program. When you add a resource, the actual file itself is copied into your project. Visual Studio 6 provides a whole collection of icons in the folder ... C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons To go with tradition, we'll select the Greek philosopher Aristotle's four "elements" - Earth, Water, Air, and Fire - from the Elements subdirectory. When you add them, the Id is assigned by Visual Studio (101, 102, 103, and 104) automatically. To use the icons in a program, we use a VB 6 "Load Resource" function. There are several of these functions to choose from:
Use the VB predefined constants vbResBitmap for bitmaps, vbResIcon for icons, and vbResCursor for cursors for the "format" parameter. This function returns a picture that you can use directly. LoadResData (explained below) returns a string containing the actual bits in the file. We'll see how to use that after we demonstrate icons.
As noted earlier, this function returns a string with the actual bits in the resource. These are the values that can be used for format parameter here:
2 Bitmap resource 3 Icon resource 4 Menu resource 5 Dialog box 6 String resource 7 Font directory resource 8 Font resource 9 Accelerator table 10 User-defined resource 12 Group cursor 14 Group icon Since we have four icons in our AboutVB.RES resource file, let's use LoadResPicture(index, format) to assign these to the Picture property of a CommandButton in VB 6. I created an application with four OptionButton components labeled Earth, Water, Air and Fire and four Click events - one for each option. Then I added a CommandButton and changed the Style property to "1 Graphical". This is necessary to be able to add a custom icon to the CommandButton. The code for each OptionButton (and the Form Load event -- to initialize it) looks like this (with the Id and Caption changed accordingly for the other OptionButton Click events): Private Sub Option1_Click()To download this complete project Click Here |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


