Take a look for ScriptoMatic2 which is a free app by the MS Guys. It writes scripts to do Windows Level things. You may be able to alter it that way, or possibly in the registry. I think you'd have to re-start the machine for them to take effect, though.
You're gonna need the following APIs :
GetSystemDefaultLCID
GetLocaleInfo
SetLocaleInfo
EnumDateFormats
PostMessage
CopyMemory
So, let's put all these (alongwith the associated Constants - and the functions using these APIs) in to a module :
Code:
Option Explicit
Public Const LOCALE_SLANGUAGE As Long = &H2
Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const DATE_LONGDATE As Long = &H2
Public Const DATE_SHORTDATE As Long = &H1
Public Const HWND_BROADCAST As Long = &HFFFF&
Public Const WM_SETTINGCHANGE As Long = &H1A
Public Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Declare Function EnumDateFormats Lib "kernel32" _
Alias "EnumDateFormatsA" _
(ByVal lpDateFmtEnumProc As Long, _
ByVal Locale As Long, _
ByVal dwFlags As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Public Declare Function SetLocaleInfo Lib "kernel32" _
Alias "SetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String) As Long
Public Function fGetUserLocaleInfo(ByVal lLocaleID As Long, _
ByVal lLCType As Long) As String
Dim sReturn As String
Dim lReturn As Long
lReturn = GetLocaleInfo(lLocaleID, lLCType, sReturn, Len(sReturn))
If lReturn Then
sReturn = Space$(lReturn)
If lReturn Then
fGetUserLocaleInfo = Left$(sReturn, lReturn - 1)
End If
End If
End Function
Public Function theEnumDates(lDateFormatString As Long) As Long
theEnumDates = 1
End Function
Private Function GetStrFromPointer(sString As Long) As String
Dim lPos As Long
Dim sBuffer As String
sBuffer = Space$(128)
Call CopyMemory(ByVal sBuffer, sString, ByVal Len(sBuffer))
lPos = InStr(sBuffer, Chr$(0))
If lPos Then
GetStrFromPointer = Left$(sBuffer, lPos - 1)
End If
End Function
Now, add a button to your form and type this :
Code:
Private Sub Command1_Click()
Dim xCID As Long
Dim xChangedFormat As String
'
xCID = GetSystemDefaultLCID()
xChangedFormat = "MM/dd/yyyy" 'specify date format here!!!
'
If xChangedFormat <> "" Then
Call SetLocaleInfo(xCID, LOCALE_SSHORTDATE, xChangedFormat)
Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)
Call EnumDateFormats(AddressOf theEnumDates, xCID, DATE_SHORTDATE)
MsgBox "Date Changed to MM/dd/yyyy format"
End If
End Sub
Try this, I honestly haven't tested this thoroughly, but it should work
Another much simpler option may be to run the regional Settings applet from within your program. basically, it will open the Regional settings dialog box, and let the user change the date formats and stuff. Add this to a button click :
Code:
Private Sub Command2_Click()
Call Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl")
End Sub
I hope this helps a bit!
Last edited by HanneSThEGreaT; October 20th, 2007 at 01:58 AM.
Thanks Hannes for that answer. I will reply you after testing it.
Meanwhile another answer bugs me regarding using dates in the access query.
Most of the members have told me not to change the user settigs of the date. As the same may effect them somehow. Can you give me any possible solution regarding using of date ranges in SQL search.
Is it possible to know without the use of any API what is the present date format (long & Short) of the system.
Actually i am bumping into the problem when i fire a query into access 2000 without giving any attention to the date format of the system. If the system date is set to mm/dd/yyyy then the date such as 12/31/2006 is perfectly interpreted whereas 05/06/2006 (5th June 2006) as 5th May 2006. Hence the results returned is not correct.
I know many may have bumped into this problem. I think there may be a possible solution regarding using date formats without depending on the system date format set in the regional settings.
Any further help....
Thanks always
regards
Amarjit
Try, Try Hard, Try Harder one day you will Succeed.
hi,
just wanna try to help, i dont know whether this can give you any solution
what if you try to use the DatePart Function, so that whatever the format of the date, the datepart always give u the right answer.
ex :
MM/DD/YYYY => 10/12/2006
DD/MM/YYYY=> 12/10/2006
Code:
dim d,m, y as string
dim dates
dates = "12/10/2006"
d = datepart("d",dates)
m = datepart("m", dates)
y = datepart ("y", dates)
Private Const LOCALE_SSHORTDATE As Long = &H1F
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" ( _
ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Function GetDateFormat() As String
Dim Val_x As Long
Dim Simbolo As String
Dim r1 As Long
Dim r2 As Long
Dim p As Integer
Dim Locale As Long
Val_x = LOCALE_SSHORTDATE
Locale = GetUserDefaultLCID()
r1 = GetLocaleInfo(Locale, Val_x, vbNullString, 0)
Simbolo = String$(r1, 0)
r2 = GetLocaleInfo(Locale, Val_x, Simbolo, r1)
p = InStr(Simbolo, Chr$(0))
If p > 0 Then
GetDateFormat = Left$(Simbolo, p - 1)
End If
End Function
test
Code:
Private Sub Command_Click()
Dim Sd() As String
Dim DateFormat As String
DateFormat = GetDateFormat
Sd = Split(DateFormat, "/")
Debug.Print DateFormat
Debug.Print Sd(0)
Debug.Print Sd(1)
Debug.Print Sd(2)
End Sub
and here with i attached the project which is converted from VB6 to VB.Net2005. Kindly check this. Totally it shows 6 errors when i Build the project.
the following error repeats.
Error 1 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.
Error 4 'As Any' is not supported in 'Declare' statements.
i changed the Any to Object its ok fine. But the AddressOf is not working. I don't know how to change it as Delegate. Can you pls modify and send me the attached project.
Are you sure ¿ Then I should have mentioned it there ( I mentioned it there now ). I did something similar in any case, so there must have been a confusion somewhere. Sorry about that, it's difficult if you have hundreds of stuff.
Originally Posted by itchock
and here with i attached the project which is converted from VB6 to VB.Net2005. Kindly check this. Totally it shows 6 errors when i Build the project.
Don't get me wrong, but for the 100th time people, it is not good to use the "upgrade wizard"! Mainly because of these type of errors. IMHO, it is best to redo the entire applicaton, or even try an incremental update.
Any is not supported in .NET. AddressOf works a bit differently in .NET
The proper definitions for those APIs ( for .NET ) is the following :
Code:
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Function EnumDateFormats Lib "KERNEL32.dll" Alias "EnumDateFormatsA" (ByVal lpDateFmtEnumProc As Int32, ByVal Locale As Int32, ByVal dwFlags As Int32) As Int32
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Int32, ByRef Source As Any, ByVal Length As Int32)
Private Declare Function GetSystemDefaultLCID Lib "kernel32.dll" () As Int32
Private Declare Function SetLocaleInfo Lib "kernel32.dll" Alias "SetLocaleInfoA" (ByVal Locale As Int32, ByVal LCType As Int32, ByVal lpLCData As String) As Int32
Private Declare Function GetLocaleInfo Lib "kernel32.dll" Alias "GetLocaleInfoA" (ByVal Locale As Int32, ByVal LCType As Int32, ByVal lpLCData As String, ByVal cchData As Int32) As Int32
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.