Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting Regional Date Settings  Format.

Posted on 2002-03-14
3
Medium Priority
?
467 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 600 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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