Microsoft KB Archive/168793

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


Article ID: 168793

Article Last Modified on 1/19/2007



APPLIES TO

  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
  • Microsoft Excel 97 Standard Edition
  • Microsoft Word 97 Standard Edition



This article was previously published under Q168793

SUMMARY

This article presents a step-by-step example on how to programmatically change the short date format of the system's Regional Settings. Otherwise the short date format can be manually changed through the Regional Settings applet in Control Panel.

MORE INFORMATION

Step-by-Step Example

  1. In a new or existing project, add a form (Form1).
  2. Add a CommandButton (Command1) to the form.
  3. Add the following code to the General Declarations section of Form1:

              Option Explicit
    
          Private Const LOCALE_SSHORTDATE = &H1F
          Private Const WM_SETTINGCHANGE = &H1A
          'same as the old WM_WININICHANGE
          Private Const HWND_BROADCAST = &HFFFF&
    
          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 PostMessage Lib "user32" Alias _
              "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
              ByVal wParam As Long, ByVal lParam As Long) As Long
          Private Declare Function GetSystemDefaultLCID Lib "kernel32" _
              () As Long
                            
  4. Place the following code in Command1_Click event procedure:

          P  Private Sub Command1_Click()
             Dim dwLCID As Long
             dwLCID = GetSystemDefaultLCID()
             If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd-MMM-yy") _
                = False Then
                MsgBox "Failed"
                Exit Sub
             End If
             PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
          End Sub
                            
  5. Run the program and open the form. Click on Command1 and then exit the program.
  6. Go to Control Panel and double-click on the Regional Settings icon. Select the Date tab. Note that the Short date style has been changed to "dd-MMM-yy."


Keywords: kb32bitonly kbhowto kbprogramming KB168793