Question Regarding CultureInfo

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
From my understanding, globalizing your VB application should convert times and dates in other countries to whichever country you specify in the Culture Info. Is this not correct?

I've got the following lines located in my Form1_Load..But it doesn't seam like the cultureinfo is actually being set. Is there some way I can verify this or is there something I'm doing wrong?

VB.NET:
'=========================Line Needed To Globalize App============================
Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
'=================================================================================
 
For example after you've set threads CurrentCulture, the date will be formatting as string accordingly:
Dim s = Date.Now.ToString

You will get same effect if you don't change threads CurrentCulture and instead use the CultureInfo as IFormatProvider:
Dim s = Date.Now.ToString(Globalization.CultureInfo.GetCultureInfo("en-US"))

Same goes for other methods that either use default/current culture or allow you to specificy culture for that call, for example the opposite Date.Parse for String to Date conversion.

About CurrentUICulture:
Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run time.
You can for example set form Localizable to True and choose Language, then set language specific text for controls in designer. These will be used if computer is set to that culture, or if you manually set CurrentUICulture. Note that this must be set before the form runs its InitializeComponent method containing the designer code, where resource mananger retrieves these texts, therefore you would override Sub New and change UI culture before the InitializeComponent call. This probably has best use for debugging when you don't want to change machine culture.
 
Back
Top