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 I
.
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:
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."