Topic: VB.Net: Write multi-culture code.

baabaa_nl
baabaa_nl used Ask the Experts™
on
Hi Experts,

I developed an application using an US and UK culture computer, and deployed it on a computer that had European culture such as Dutch, and my application did not work properly as intended. I found the reason for the cause and that was because, I was using decimal point '.' for the currency rather than the comma ',', which is used by the European culture. I was then given a solution by an expert on Experts Exchange to use the CultureInfo.CurrentCulture.NumberFormat.numberdecimalseparator. And since then it worked without any problem.

But I want to make sure that the code I write is always a multi culture application. How can I do that. Because the application I develop will be used by many users which will have different languages installed on the computer with different keyboard layouts. So is there a way or method that I should follow that when I write a code once in VB.Net and it will work as intended on other cultured computers without me writing separate codes for each and every culture that will be used by the user.

I also faced a similar problem in Access and Excel using the same above application(the application uses the database to fill the datagridview and for the user to add and manipulate the database of income and outgoing funds).

In Access database I had an issue with dates(the user is only able to access the Access database by using the VB.Net application), i.e. when user entered the date 5/9/2012, the Access stored the date as 9th May 2012, because the Access was in US. So to solve that, I had to  change the number of the month with the name. At first I used the .ToString("MMMM") to convert the number of the month to the name of the month, so that it would be sent to the database as 5/May/2012, but when I did this on a European culture computer and tried to send the date to the Access database, it threw an error, because the May was sent 'Mei'(the May month in Dutch) and Access could not recognize the Dutch name of the month. So I wrote a custom method that converts the number of the month to the name(names of the month in English) and then passed it to the Access. But is there any way that I could do that in a multi culture way, i.e. send the month in a multi culture way that any language of Access can recognize it. Because I am developing this application using an US Access, but on the deployment location, the users will most probably using a Dutch version of Access Database. So there is a possibility that the date my cause problems on the Dutch version of the Access.

Hope I was clear with my question.

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I have come accross such issues when distributing my applications and have come up with the following methods to overcome them.
1. Numbers. I stick to letting the system culture determine their format, by for example setting default values by using FormatNumber(0, 2) which will produce 0.00 for US and 0,00 for EU cultures.
2. Dates - For these, I always set a mask for any date, and if necessary set its database type to string rather than datetime, e.g Date.Today.ToString("dd/MM/yyyy") so that the program always knows what format the date is in.
There could be other structured ways in which to achieve this, but I found this to be the easiest and most fool-proof.
Commented:
To add to the above, using the generic methods to validate entries are dates / numbers is straight foward and "forces" the user to enter values intheir system culture, which I assume they are familiar with. For example, applying the function IsDate() to a value entered into a textbox / grid by the user will assume the date format is in the UI / system culture.

Author

Commented:
by settings the date fields to string, is it possible to query data between two dates? since if the date field is set to a string?

Also are there any website or links that shows the places and areas where multi culture code should be used to make sure that the application works on a multi culture platform.

Thanks in advance.
Commented:
I do not have much experience with access, but with LINQ to SQL it is very simple to query data between dates stored as strings by simply casting the date (string) field as a Date.

I am sure there are a few sites about on a clearly important subject, but have none in my favourites! I'd suggest doing a search on  MSDN.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial