Solved

Setting Regional Date Settings  Format.

Posted on 2002-03-14
3
458 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]
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

803 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