moongodess Posted May 2, 2005 Posted May 2, 2005 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??? Quote
Moderators Robby Posted May 2, 2005 Moderators Posted May 2, 2005 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. Quote Visit...Bassic Software
moongodess Posted May 3, 2005 Author Posted May 3, 2005 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!! Quote
Moderators Robby Posted May 4, 2005 Moderators Posted May 4, 2005 To iterate a control such as a panel... For each x in Panel1.Controls Quote Visit...Bassic Software
Leaders snarfblam Posted May 4, 2005 Leaders Posted May 4, 2005 exactly. try something like this: 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). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.