*

VB Database: Challenge Lab Week 1

I would like you to read up on using Resource Files on MSDN:

Then, add the attached resource file (china.res) to the Lesson 1 China Shop project and change the following procedure:

Private Sub lstBrands_Click()
   If lstBrands.ListIndex = -1 Then Exit Sub
   Dim intIndex As Integer
   intIndex = 101 + lstBrands.ListIndex 'zero based collection
   imgChina.Picture = LoadResPicture(intIndex, vbResBitmap)
End Sub

For added fun:

  • Change the MsgBox prompts in Private Sub cmdCalculate_Click() to load from the Resource File.  There are strings there for "You must select a China brand" (201), "You must select one or more china items" (202), and "You must select a quantity" (203)

    For example:

    'Has the customer selected a brand of china?
       If lstBrands.Text = "" Then
          MsgBox LoadResString(201)
          Exit Sub
       End If
  • After testing this successfully, go into the  Regional Options Control Panel and change the Settings for Current User setting to first French (France) and then Spanish (Mexico).  Run the program again with each.  (You can blame babelfish.altavista.com for any translation mishaps :-) Voila! Instant localization!  (BTW, the original string table is English (United States))

If you would like to create your own resource file using the Resource Editor Tool/Add-in, I've also attached a zipped set of the china images saved as bitmaps instead of gifs.  Please also feel free to modify the resource file string tables with other appropriate strings and post your projects here for the other students to see.

Microsoft has a Knowledge Base article on a sample project (resfile.exe) that shows how to store any file type in a resource file and retrieve the file for use at run-time (LoadResData function).

Questions to ponder:

  1. Why on earth do we care about resource files?
  2. What happens to the resource file during compile, package and distribution?
  3. How many resource files can be in a project?
  4. Is there a past, present, or future project that could benefit from using a resource file?
  5. Do you think you will use resource files?
  6. If Peter Piper picked a peck of pickled peppers, how many pickled peppers did Peter Piper pick?

P.S. I found this link to a product specifically designed for working with Resource Files in VB.  I haven't used it, but it sounds interesting.

Download Proposed Solution



Internet Content Rating Association Valid CSS!

Alrak's Course Resources ©2002-2007 Karla Carter. All rights reserved. This material (including, but not limited to, Mini-lectures and Challenge Labs) may not be reproduced, displayed, modified or distributed without the express prior written permission of the copyright holder. For permission, contact Karla.