Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Multi Language problems

Multi Language problems

Multi Language problems

Using the Resource editor I've set up a number of string tables for different languages. VB picks the string table to use by looking at the Regional setting of the PC, and in most cases this works fine. However, in a few cases I need to override the automatic selection. For example, the Region could be "Italian(Standard)" but I may want to force the App to use "English". How can I do this?

RE: Multi Language problems

I see by your other threads you have been trying for a year to get this working.

This is a slight problem with the VB resource file, as you cannot identify the LCID to use, and you cannot have more than one resource within the same project, at least not that I know of.

What I would suggest to do is to create two new different VB projects each with a different resource file: One just in English (not just the text, but also the country id selection is "English x") as default, and one with all languages (you can just copy the *.RES file and in the copy remove all other languages)
Every change made in the Multi-language resource file you will need to repeat the file copy and columns delete

Start two new seperate ActiveX Dll projects, each with their own resource file as mentioned above.

Add a public MultiUse class with some functions which act as wrappers for the VB resource loading functions(such as LoadResData) which extract the data from the resource file.
Create the Dlls each with a different name.

In your main project have a property to identify which resource dll to use, and then use CreateObject() to use the one desired, or set a reference to both dlls, , and call the class methods of that dll to get the ressource string.

RE: Multi Language problems

>This is a slight problem with the VB resource file

No, the problem is firstly that there is no option to change locale within VB, and even if you do VB's LoadResString function fails to take account of it ...

Basically if you drop LoadResString and use the API version (which really isn't that much harder to use) instead then we can achieve the desired result.

Here is an example which assumes you have a RES file with at least two string tables (one being the default language, the other of which should be 'French (France)'). Then you need a command button. And the following code:


Option Explicit

Private Declare Function SetThreadLocale Lib "kernel32" (ByVal Locale As Long) As Long
Private Declare Function GetThreadLocale Lib "kernel32" () As Long
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long

Private Sub Command1_Click()
    Dim result As Long
    result = GetThreadLocale ' save current thread locale
    MsgBox vbLoadResString(101) ' Ok, display current locale string
    SetThreadLocale (&H40C) 'Set locale of this thread to French (France) for this example
    MsgBox vbLoadResString(101) ' Now display French language string
    SetThreadLocale result ' Set locale back to original
    MsgBox vbLoadResString(101) ' Display string for original locale
End Sub

' Warning this replacement for the LoadResString only work's in compiled programs
' because of the use of App.hInstance in the LoadString function
Public Function vbLoadResString(id As Long) As String
    vbLoadResString = Space(256)
    LoadString App.hInstance, id, vbLoadResString, Len(vbLoadResString)
End Function
Note that this will only work when the program is compiled as we are seeking the resources in t the application instance - and in the IDE they are not held in the app.

This trick can also be pulled for other localized resources in the VB RES file (bitmaps, icons, cursors,  and other binary data)

RE: Multi Language problems

>>This is a slight problem with the VB resource file

>No, the problem is firstly that there is no option to change locale within VB,

Isn't that what I mentioned, at leat what is meant, when the next part of the statement is considered?:
>... as you cannot identify the LCID to use

Anyways, the nice part about using dll solution is it prevents the VB RES from bloating the size of the Exe.
So using that, a single resource dll, in conjunction with SetThreadLocale, seeems to be a nice overall solution for a VB Resource file.

RE: Multi Language problems

Ah, but the implication in your original post seemed to be that the issue was a shortcoming of the VB RES file functionality, which it isn't. I'm sorry if I misinterpreted what you were saying.

RE: Multi Language problems

I see what you mean - bad wording on my part. Where I said "cannot identify " you said "no option" and that was the same for me in this manner and how I meant it. Sorry about the misunderstanding.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close