0

I am writing an application in VB.NET which will run on systems where the culture settings recognize comma (,) as the decimal marker, but I would like program to use the punctuation (.) as a decimal marker.

I know I can use the System.Globalization.CultureInfo.InvariantCulture, but I don't want to bring this into every ToString() operation that I do. I figure it must be possible to set the culture settings globally for the program on startup, but I don't know how.

I have tried this: I found a question here on stackexchange stating that

Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture

can be used in C# and in my experience C# and VB.NET are pretty much the same, so I attempted to use this. I couldn't just reference Thread so I figured I'd try

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture

and since I didn't know where to put it, I placed it in the Load method for the splash screen. Alas, that did not work for me.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
zo0x
  • 136
  • 1
  • 6
  • This is a really bad idea. The culture settings are there for a reason so that the end user can see the values in their own locale. Forcing them to use a locale that they are not familiar with is confusing and will lead to error. – Matt Wilko Aug 19 '15 at 11:47
  • This is an application for a group of people used to working in MATLAB, they are all used to punctuation as the decimal marker. So familiarity is definitely not the reason I should not to do this. – zo0x Aug 19 '15 at 11:55
  • You are asking that every time there is a new employee in the department they should change their computers locale settings for this one application, that sounds like a terrible idea if the application could be made to work without doing that. – zo0x Aug 19 '15 at 12:00
  • No I am not saying that. I am saying that they set the locale to whatever is appropriate to them and your application should work with whatever locale they decide to use. – Matt Wilko Aug 19 '15 at 12:03
  • I don't really have the options you are suggesting. I have been asked to do the application this way, I don't have any mandate to change everyone's locale, if I could I would have long ago. So if you are not offering a solution to the actual problem I have, then I can't really use it. – zo0x Aug 19 '15 at 12:12
  • You said it doesn't work for you. In what way does it not work? Does it throw an exception (be careful that it's not throwing an exception and it's just being caught by a try/catch and leaving you unaware)? On a side note, is your application multi threaded? – Steven Doggart Aug 19 '15 at 12:23
  • 1
    I would expect a splash screen to be run in a different thread from the "main" form. – Andrew Morton Aug 19 '15 at 12:27
  • Try to not put it in any method, but just in the class itself. Maybe this'll help: https://msdn.microsoft.com/en-us/library/b28bx3bh(VS.80).aspx – Visual Vincent Aug 19 '15 at 12:33
  • @StevenDoggart: Nothing the happened, the program ran as usually, the culture settings in the program in general was simply not changed. Regarding multithreading: I have not actively tried to make the program multithreaded, but maybe different forms are on different threads as Andrew Morton suggests? It seems to be the case, as moving the line into another forms code actually fixes it for the form. I wasn't aware of that. That seems to do the trick, but I guess I need to have the line in every form I make. – zo0x Aug 19 '15 at 12:49
  • Well, technically just once per thread, but yes, I suppose setting it multiple times won't hurt anything. – Steven Doggart Aug 19 '15 at 12:51
  • This seems to work for me, thanks a lot. – zo0x Aug 19 '15 at 13:20
  • I can confirm that if you use the application framework splash screen this does indeed run on a separate thread from the main application – Matt Wilko Aug 19 '15 at 13:33

0 Answers0