Solved

Setting Regional Date Settings  Format.

Posted on 2002-03-14
3
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

615 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