MitchSavage
asked on
Get Regional Settings from Windows PC
How can I retreive the Regional Date Settings from a Windows PC. I have a vb application, I want a label to display the date format used on the PC. Example:
dd/mm/yyyy or mm.dd.yy or mm/dd/yyyy etc. Retreiving any other settings such as the time format etc... would be helpful. How to retreive this string from the system?
dd/mm/yyyy or mm.dd.yy or mm/dd/yyyy etc. Retreiving any other settings such as the time format etc... would be helpful. How to retreive this string from the system?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This code retrieves the short date format set in Regional Settings in the computer, and sets to "mm/dd/yyyy" this configuration.
Just add 2 command buttons to the project (command1 retrieves, command2 set), and paste the code below:
'''''bas module code
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
Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Declare Function GetUserDefaultLCID% Lib "kernel32" ()
Public Const LOCALE_SSHORTDATE = &H1F
'''''end of bas module code
'''''form code
Public Sub Get_locale() ' Retrieve the regional setting
Dim Symbol As String
Dim iRet1 As Long
Dim iRet2 As Long
Dim lpLCDataVar As String
Dim Pos As Integer
Dim Locale As Long
Locale = GetUserDefaultLCID()
iRet1 = GetLocaleInfo(Locale, LOCALE_SSHORTDATE, lpLCDataVar, 0)
Symbol = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LOCALE_SSHORTDATE, Symbol, iRet1)
Pos = InStr(Symbol, Chr$(0))
If Pos > 0 Then
Symbol = Left$(Symbol, Pos - 1)
MsgBox "Regional Setting = " + Symbol
End If
End Sub
Public Sub Set_locale() 'Change the regional setting
Dim Symbol As String
Dim iRet As Long
Dim Locale As Long
Locale = GetUserDefaultLCID() 'Get user Locale ID
Symbol = "mm/dd/yyyy" 'New character for the locale
iRet = SetLocaleInfo(Locale, LOCALE_SSHORTDATE, Symbol)
End Sub
Private Sub Command1_Click()
Get_locale
End Sub
Private Sub Command1_Click()
Set_locale
End Sub
'''''end of form code
ppaulinolopes, interesting code.
ameba: COOL!
ameba, your code is interesting but it does not work for me. ppaulinolopes's is the correct one.
hongjun
hongjun
hongjun,
you are right, I was only trying to use one-liner
Private Sub Form_Click()
Caption = Replace(Replace(Replace(Re place(Form at(DateSer ial(2000, 11, 22), "Short Date"), _
"22", "dd"), "11", "mm"), "20", "yy"), "00", "yy")
End Sub
you are right, I was only trying to use one-liner
Private Sub Form_Click()
Caption = Replace(Replace(Replace(Re
"22", "dd"), "11", "mm"), "20", "yy"), "00", "yy")
End Sub
Btw, hongjun, nice single-page profile ;-)
>>Btw, hongjun, nice single-page profile
Thanks
hongjun
Thanks
hongjun
I would like to say something since the code posted by
ppaulinolopes is similar to mine.
I posted a code that you could use for every value on reginal settings of Control Panel applet (as you asked on question), not only date.
Cheers
ppaulinolopes is similar to mine.
I posted a code that you could use for every value on reginal settings of Control Panel applet (as you asked on question), not only date.
Cheers
ASKER
ppaulinolopes's code is in fact very interesting. I am using the code posted by Richie Simonetti. Richie's code is working so I am awarding Richie the points. Thanks everyone for your help.
Best Regards to all
Mitch......
Best Regards to all
Mitch......
ASKER
Richie Simonetti,
Sorry it took so long to respond and award points. I had to make a few mods here and there to my program, but now I have exactly what I want. I'm also using some of the other regional items that you provided the correct code for. So, Thanks alot for the help.
Best Regards,
MitchSavage.....
Sorry it took so long to respond and award points. I had to make a few mods here and there to my program, but now I have exactly what I want. I'm also using some of the other regional items that you provided the correct code for. So, Thanks alot for the help.
Best Regards,
MitchSavage.....
You are welcome anytime!
Cheers
Cheers
One more comment about this question:
1) The code posted by Richie_Simonetti really works
2) The code posted by ppaulinolopes really works too
3) Richie_Simonetti was faster then ppaulinolopes
4) Richie_Simonetti should award the points
5) That's the life
See you, guys...
Caption = Replace(Replace(Replace(Fo
"22", "dd"), "11", "mm"), "2000", "yyyy")
End Sub