The information in this article applies to:
- Microsoft Visual Basic Control Creation, Learning, Professional, and
Enterprise Editions for Windows, version 5.0
- Microsoft Visual Basic Standard, Professional, and Enterprise Editions,
32-bit only, for Windows, version 4.0
- Microsoft Access versions 7.0, 97
- Microsoft Excel 97 for Windows
- Microsoft Word 97 for Windows
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
- In a new or existing project, add a form (Form1).
- Add a CommandButton (Command1) to the form.
- 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
- Place the following code in Command1_Click event procedure:
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
- Run the program and open the form. Click on Command1 and then exit the
program.
- 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 : vb432 VB4WIN vb5all vb5howto VBKBDLL VBKBWinAPI vbwin GnrlVb kbprg
Technology : kbvba
Version : WINDOWS:4.0 5.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto
|