Rick Okrasinski
February 2nd, 1999, 05:44 PM
I want to change the way the system formats the date in the registry. If a users setting default to m/d/yy I want to change it to mm/dd/yyyy.
Thanks
Rick
Thanks
Rick
|
Click to See Complete Forum and Search --> : How do you change registry setting using VB?? Rick Okrasinski February 2nd, 1999, 05:44 PM I want to change the way the system formats the date in the registry. If a users setting default to m/d/yy I want to change it to mm/dd/yyyy. Thanks Rick Chris Eastwood February 3rd, 1999, 02:59 AM Hi You don't have to get the date format from the registry at all. The Win32 api allows you to get various information from the computers international setup (dateformat, thousand separator, currency symbol etc). I also wouldn't recommend trying to change the users dateformat on their machine. This could cause all kinds of problems if other programs on their system aren't as good as yours ;-) I'd recommend obtaining the existing dateformat from the computer and having a routine you call to use your own date format - this ensures that your code is portable to other countries / languages (eg. In europe, we use DD/MM/YY or DD/MM/YYYY, which inside code, we always refer to as YYYY/MM/DD - this ensures that date formats from other countries can always be 'exported' again correctly). Here's a code snippet. Place the declares in either a BAS module or in your form (changing private / public as required) : ' ' Locale Constants ' Public Const LOCALE_SDECIMAL = &HE Public Const LOCALE_SLONGDATE = &H20 Public Const LOCALE_SSHORTDATE = &H1F Public Const LOCALE_SCURRENCY = &H14 Public Const LOCALE_STHOUSAND = &HF Public Const LOCALE_SINTLSYMBOL = &H15 Public Const LOCALE_STIMEFORMAT = &H1003 Public Const LOCALE_USER_DEFAULT As Long = &H400 Public Declare Function GetLocaleInfo Lib "KERNEL32" _ Alias "GetLocaleInfoA" (ByVal lLocale As Long, _ ByVal lLocaleType As Long, ByVal sLCData As String, _ ByVal lBufferLength As Long) As Long Public Declare Function GetSystemDefaultLangID Lib _ "KERNEL32" () As Integer Public Declare Function VerLanguageName Lib "KERNEL32" _ Alias "VerLanguageNameA" (ByVal wLang As Long, _ ByVal szLang As String, ByVal nSize As Long) As Long Now, place the following routine in a BAS module (or wherever you want it) : Public Function GetDateFormat() As String ' ' This function will return the Locale date format for the system. Note that the ' returned Year is always formatted to 'YYYY' regardless, to ensure compliance with ' Y2k stuff. ' Dim lBuffLen As Long Dim sBuffer As String Dim lResult As Long Dim sDateFormat As String On Error GoTo vbErrorHandler lBuffLen = 128 sBuffer = String$(lBuffLen, vbNullChar) lResult = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sBuffer, lBuffLen) If lResult > 0 Then sDateFormat = Left$(sBuffer, lResult - 1) ' ' Make sure we always have YYYY format for y2k ' If InStr(1, sDateFormat, "YYYY", vbTextCompare) = 0 Then ' ' Write your own routine to replace YY with YYYY ' Replace sDateFormat, "YY", "YYYY" ' End If GetDateFormat = sDateFormat Else GetDateFormat = "DD/MM/YYYY" End If Exit Function vbErrorHandler: Err.Raise Err.Number, "GetDateFormat", Err.Description End Function Now, whenever you need to access the systems date format, use something like : sSysdateFormat = GetDateFormat or : dteDate = Format(sDateValueValue, GetDateFormat) In the GetDateFormat routine, you can apply your own internal format to however you want, ie. MM/DD/YY, M/D/YY etc Regards Chris Eastwood -Zafir CodeGuru - the website for developers codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |