What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleLoad internationalization data from a resource file with a single string table
Keywordsdatabase, internationalization, language, resource file
CategoriesDatabase, Software Engineering
To install the resource editor, select the Add-In menu's Add-In Manager command. Click on the VB 6 Resource Editor. Check the Load/Unload and Load on Startup boxes. Then click Ok.

At the bottom of the Project menu, select Add New Resource File command. Now you can use the resource editor to edit the resource file.

This example uses one string table. Corresponding values for different languages are stored with the same numeric value plus a language offset. In this example, English has an offset of 0, French has an offset of 1000, and German has an offset of 2000. The "Yes" strings have a base value of 2 so the values in the table are:

    Value    ID
    -----    ----
    Yes         2
    Oui      1002
    Ja       2002

The program uses LoadResData, LoadResPicture, and LoadResString to load its data. It selects resources by adding the selected language's offset to the string's base ID.

' Languages are offset by 1000.
Private Enum LanguageOffsets
    langEnglish = 0
    langFrench = 1000
    langGerman = 2000
End Enum

' String IDs start at 1.
Private Enum StringIDs
    resCaption = 1
    resYes = 2
    resNo = 3
    resPrompt = 4
    resLanguage = 5
    resLanguageEnglish = 6
    resLanguageFrench = 7
    resLanguageGerman = 8
End Enum

' Picture IDs start at 101.
Private Enum PictureIDs
    respicYes = 101
    respicNo = 102
End Enum

Private Sub optLanguageEnglish_Click()
    LoadStrings langEnglish
End Sub

Private Sub optLanguageFrench_Click()
    LoadStrings langFrench
End Sub

Private Sub optLanguageGerman_Click()
    LoadStrings langGerman
End Sub

' Load the strings for this language.
Private Sub LoadStrings(ByVal offset As Integer)
    ' Load strings.
    Caption = LoadResString(resCaption + offset)
    cmdYes.Caption = LoadResString(resYes + offset)
    cmdNo.Caption = LoadResString(resNo + offset)
    lblSavePrompt.Caption = LoadResString(resPrompt + _
    fraLanguage.Caption = LoadResString(resLanguage + _
    optLanguageEnglish.Caption = _
        LoadResString(resLanguageEnglish + offset)
    optLanguageFrench.Caption = _
        LoadResString(resLanguageFrench + offset)
    optLanguageGerman.Caption = _
        LoadResString(resLanguageGerman + offset)

    ' Load images.
    cmdYes.Picture = LoadResPicture(respicYes + offset, _
    cmdNo.Picture = LoadResPicture(respicNo + offset, _
End Sub
This method has the advantage that you can change the language after the prorgam is already loaded.
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.