Improve company productivity with a Business Account.Sign Up


vb6 project to handle european languages

Posted on 2001-07-24
Medium Priority
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!
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

606 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