Solved

Setting Regional Date Settings  Format.

Posted on 2002-03-14
3
460 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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6867575
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
ID: 6869583
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
ID: 6870616
Thank  you very  much Cnealy.
It has  solved a major  headache  for me.

Regards
Vikarnt  
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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