vb6 project to handle european languages

Posted on 2001-07-24
Last Modified: 2008-02-01
How can i make my vb6 project to support different european languages. i have log all the string that the  program display, i have over 2000 different strings. i was thinking of using resource files ?? is this the only way ??? if not what is the better way ?? please help.
Question by:LPlate

Expert Comment

ID: 6311994
I had to do this for a project which needed to be able to change the language at runtime without a restart.

We used an Access database (3000 strings) and used the AbsolutePosition settings to get each string.

It means loading the strings on each form as the form loads, but it does not seem to take much time for us since we open the recordset at program startup to keep all the strings ready.

A simple function call like GetString(1023) will return the string in the recordset at position 1023:>

Function GetString(TheNO as Long)
    MyLangStr.AbsolutePosition = TheNo
    GetString = MyLangStr.Fields("String")
End Function

Dont know if this will help you but it may be an idea to give it a try. One thing though. You CANNOT delete or move items in the database sine this will mess up the AbsolutePosition of all the others.

Good luck...


Expert Comment

ID: 6311998
Forgot to mention that of course in the example above, the recordset MyLangStr is global. It gets opened when the program starts and is ready to go while it is running.

Good Luck...

Expert Comment

ID: 6312003
If you don't want to use a resource file you could put a string ID in the Tag property of each control that will use a string.

Put all of your multi language strings into a database file with a language code and the string ID as the key.

When you start the application ask the user for a language code or retrieve it from the registry.

When you load the form read through all of the controls on it and if the Tag property contains a value, go and get the appropriate record from the database and populate the control's Text or Caption property.

Here's a routine for reading through all of the controls on a form.

Public Sub ShowMandatoryControls(myForm As Form)
   'Set the background and foreground colours for text boxes
   'depending on whether they're mandatory and/or empty
   Dim myControl As Control
   For Each myControl In myForm.Controls
      If TypeOf myControl Is TextBox Or _
         TypeOf myControl Is DataCombo Then
         If UCase(myControl.Tag) = "M" And _
            Trim(myControl.Text) = "" Then
            myControl.BackColor = vbYellow
            myControl.ForeColor = vbBlack
            myControl.BackColor = vbWindowBackground
            myControl.ForeColor = vbWindowText
         End If
      End If

End Sub

I guess, when it comes down to it, that's what resource files are doing!
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Expert Comment

ID: 6312736
There are two ways to go here:

1. Use a resource file with multiple string tables, one for each language you wish to use.

Resource files created with the Resource Editor can contain multiple string tables, each containing strings localized for a different language. A string table will automatically be selected at run-time based on the LCID of the system; if a match isn?t found the system will load the first string table in the resource file. This model is advantageous for creating an application which will be distributed for two or more languages with no requirement for multi-language support within a single instance.

2. If you wish to dynamically select the language i.e. at run time then you can use the following approach.

Ok there is a way of doing this without changing the default locale on the machine.

Create two new ActiveX DLL projects (number of projects depends on the number of languages required
but for this example two will suffice).

Name the projects as follows

Rename Class1 in both cases Resource

Using the Resource Add in in Visual basic add a resource to each project name the .Res files LocaleEnglish
and LocaleIrish.

Just for example add "How Are You" to the LocaleEnglish resource and "Conas ata tu" to the LocaleIrish

Add the following code to each class module.

Public Function GetResourceString(ResourceIndex As Long) As String
        GetResourceString = LoadResData(ResourceIndex, 6)
End Function

Make both ActiveX DLLs. Save the projects and close them.

You now have a means of switching between resources in your code.

Just do the following and test it.

Dim objLocalised as Object
Dim strLanguage as String
strLanguage = "English"

objLocalised = CreateObject("Locale" + strLanguage + ".Resource")

Dim strTemp as String  
strTemp = objLocalised.GetResourceString(101)

If you change the strLanguage to "Irish" you will get the Irish version of 'How are you'.

Just repeat the process for the required languages.

That should be it.


LVL 49

Expert Comment

ID: 7161467
Hi LPlate,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.
    *** 3 Good answers, too few points to split.  Accepting recommendations, though.

LPlate, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer

Accepted Solution

Computer101 earned 0 total points
ID: 7182599
Placed in PAQ

E-E Moderator

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question