For each

moongodess

Freshman
Joined
Dec 23, 2004
Messages
40
In my project I have a collection with the texts to translate the controls.
This collection is filled when the program starts, with a number that identifies the text, and a default text.

To be easier for me, I need to do is in each form:
- define all control.tag (label, checkbox, or something similar) with a numeric value
- define all control.text with the default text

Create a sub called Translate (or something else) with something like this:

Dim a as integer, b as string

For each x in me.Controls
a = cint(x.tag)
b = cstr(x.text)
if (a > 0) then
a.text = trans(a, b)
end if
Next


where trans is the function that will return the translated text.

I tried to do this, exactly, and i saw that me.controls was not catching all the control, in the form. No label, no checkboxes, nothing!!

Does anyone has a suggestion, please???
 
If a control is in another container such as a Panel you need to iterate Panel.controls.

As a side note: why aren't you using a resource file for all your language strings, this is done with a couple of lines of code and requires little effort. There is no need to loop controls or use IF conditions to see which language is being used. It is really simple and would apply the selected language to the entire application and is scalable.
 
Robby said:
If a control is in another container such as a Panel you need to iterate Panel.controls.
How can I do this??



As a side note: why aren't you using a resource file for all your language strings, this is done with a couple of lines of code and requires little effort. There is no need to loop controls or use IF conditions to see which language is being used. It is really simple and would apply the selected language to the entire application and is scalable.
I can't do this, because the database structure is already defined, and already has a table wich contains all messages in all languages.
If I could change this, maybe it would be easier, but this is a small part o a huge project, and I must continue with what was already decided. Thanks anyway, for the suggestion. I'll consider in the future.

Thanks!!
 
exactly. try something like this:

Visual Basic:
Sub ApplyLocalization(Collection As ControlCollection)
    For Each Item As Control In Collection
        'Localization Code
        If Item.Controls.Count > 0 Then ApplyLocalization(Item.Controls)
    Next
End Sub

A recursive sub like this will automatically take care of all the controls contained within other controls. To start the whole thing up, you would just use the line ApplyLocalization(Me.Controls).
 
Back
Top