VB.Net guru's - Regional Settings

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
Right, calling all the experts now for a little something.

I need to create a small little program that sets the ShortDateFormat of Regional Settings to UK.

I can read it no probs, but setting it is giving read-only errors.

As it stands, it reads as the following...

Dim instance As DateTimeFormatInfo
Dim value As String
value = instance.CurrentInfo.ShortDatePattern
MsgBox(value.ToString)
instance.CurrentInfo.ShortDatePattern = "dd/MM/yyyy"
MsgBox("Done")

Has anyone any ideas on how to set it?

TIA
 
You can't do it that way, that's just so your code knows what locale it's in. As far as I know the only way to change it would be using a Windows API call to SetLocaleInfoA.

If you google for that function and VB you should find a few sample modules that should work on in VB.Net
 
Beepcake said:
You can't do it that way, that's just so your code knows what locale it's in. As far as I know the only way to change it would be using a Windows API call to SetLocaleInfoA.

If you google for that function and VB you should find a few sample modules that should work on in VB.Net

100% correct, and yep the SetLocaleInfoA seems to be the way to go, but all the examples I've seen are for VB6, it's as if the API is diffrent for Vb.Net :confused:
 
~J~ said:
100% correct, and yep the SetLocaleInfoA seems to be the way to go, but all the examples I've seen are for VB6, it's as if the API is diffrent for Vb.Net :confused:

If you can get a module for VB6 and paste it into a VB.Net module it should be pretty easy to 'fix up' if it doesn't work first time.
 
Well got it working. VB6 version works perfectly...

Private Const LOCALE_SSHORTDATE = &H1F
Private Const LOCALE_SLONGDATE = &H20
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Dim lLocal As Long

Sub Main()
lLocal = GetSystemDefaultLCID()
SetLocaleInfo(lLocal, LOCALE_SSHORTDATE, "dd/MM/yyyy")
SetLocaleInfo(lLocal, LOCALE_SLONGDATE, "dd MMMM yyyy")

But that doesn't work in Vb.Net! :confused:

Weird one, but got the end results. Thanks for the guidelines.
 
The WinAPI is the same for VB6 or VB.NET - Declaring the API may be slightly different but all the functions are the same.

TrUz
 
Back
Top Bottom