Visual Basic Concepts
The Automated Teller Machine Sample Application
This sample application has been designed to illustrate support for resource files in Visual Basic. The application contains three forms, a standard module, and a resource file. When you run the Automated Teller Machine (Atm.vbp) sample application, an opening screen lets you perform a bank transaction in one of several languages, including German, French, Italian, and Spanish.
The following code from the FrmInput.frm file loads resources stored in the Atm32.res file, which contains the localized strings for all languages.
Sub Form_Load() imgFlag = LoadResPicture(I, vbResBitmap) Caption = LoadResString(I) lblPINCode = LoadResString(1 + I) fraAccount = LoadResString(2 + I) optChecking.Caption = LoadResString(3 + I) optSavings.Caption = LoadResString(4 + I) lblAmount = LoadResString(5 + I) cmdOK.Caption = LoadResString(6 + I) SetCursor cmdOK End Sub Sub cmdOK_click() ' Display a process message. MsgBox LoadResString(7 + I) frmAmountWithdrawn.Show vbModal Unload Me End Sub
At run time, this code reads the appropriate section of the resource file, based on an offset that is initialized when the user makes a language selection in the opening screen. The offset is a public variable declared in the standard module that indicates how far from a starting point a particular item is located. In the ATM sample application, the offset variable is
In the resource file, resource identifiers 16 through 47 are reserved for English, 48 through 79 are reserved for French, 80 through 111 are reserved for German, and so on. Each language contains the localized entries that make up the data block of the sample application. This block currently contains the eleven resources that are particular to each language.
This sample application, which contains several data blocks, introduces an alternative to a language-specific resource file using only one data block. Depending on the nature of the application you are developing, you may consider using one resource file per language version of your application or a single resource file containing all the localized data blocks.
The design of the Automated Teller Machine sample application presents several advantages beyond the ones outlined earlier in the chapter:
The application can grow in scope by providing service in more languages. Simply add the same data block to the resource file and localize it as needed. If you decide to add a language, you may have to add a button to the opening screen.
The application can grow in size if you want to extend your application by, for instance, allowing the ATM users to make deposits. Simply allow for wider identifier ranges (160 for example) for each language in the resource file. Currently, the identifiers range from 16 to 47, 48 to 79, and so on.
*For More Information* See "LoadResString Function," "LoadResPicture Function," and "LoadResData Function" in the Language Reference. For information on resource files, see "Working with Resource Files" in "More About Programming" and "Designing for Performance and Compatibility."