Solved

Setting Regional Date Settings  Format.

Posted on 2002-03-14
3
452 Views
Last Modified: 2010-05-02
How can one set the  regional date settings format using VB. At present we are doing it through the  control panel.
we are using two  applications  which require
different date formats (MM/DD/YYYY)  and  (DD/MM/YYYY)
I  need to set this when my  user  logs  into
the  applicaton to  ensure that the  date format is
(MM/DD/YYYY) which  is  what the  application was design to use.
Thank  you.
Vikrant Patil
0
Comment
Question by:vikrantpatil
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
This is no good to force the regional settings and the application to think this setting is active:
imagine if 2 different applications start, each requesting a different date format?

If you have a date value, you can "write" it as string using the Format(yourdate, "MM\/DD\/YYYY") format. To read such a value, you can use DateSerial(y,m,d), where you split up the string value like this:

dim strDate as string
dim s() as string
dim datValue as Date
 
strDate = "2002/03/15"
s = split(strDate, "/")
datValue = DateSerial(s(0), s(1), s(2))

or

strDate = "03/15/2002"
s = split(strDate, "/")
datValue = DateSerial(s(2), s(0), s(1))

Note that the split function exists in VB6, but in VB5 you can write your own split funciton...

Cheers
0
 
LVL 1

Accepted Solution

by:
cnealy earned 150 total points
Comment Utility
If you must change the regional settings, here's how to do it.

On your startup form, declare these constants:

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

Then add this code to change the setting.  In my case, I tied this to a command button (the submit button that is pressed when a password is entered.

'change regional settings to mm/dd/yyyy
  Dim dwLCID As Long
  dwLCID = GetSystemDefaultLCID()
  If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "MM/dd/yyyy") = False Then
    'change setting
  Else
    'don't change setting
     PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
  End If
 
0
 

Author Comment

by:vikrantpatil
Comment Utility
Thank  you very  much Cnealy.
It has  solved a major  headache  for me.

Regards
Vikarnt  
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Is an IP address in a Range 22 71
VB6 convert MSHFlexgrid1 cells 7 52
Problem to delete range 4 54
Access 2016 VB code 9 86
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now