[2005] How to change Short Date format in system using VB.Net2005
Hi,
When i use a particular software in my system, it changes the Short Date format to dd/mm/yyyy. I got a piece of code which change the Short Date format in system from dd/mm/yyyy to mm/dd/yyyy and vice versa,
but its a VB6 code. I converted that project and tried in VB.Net. Its not successfull. Can any one give the code for this scenario in VB.Net 2005.
Thanks for any help.
Thanks and Regards,
V.Chock.
Re: [2005] How to change Short Date format in system using VB.Net2005
There is no managed method for doing this. You would have used unmanaged code in VB6 and you'd have to do the same in VB.NET. Whatever Windows API function you're calling in the VB6 code you will have to call also in the VB.NET code. I'll wager that you are declaring one or more arguments as type Long instead of type Integer.
Either your code won't compile or it crashes at run time. Either way you would be provided with an error message. If you want us to help fix the problem then it's incumbent upon you to provide us with that error message.
1 Attachment(s)
Re: [2005] How to change Short Date format in system using VB.Net2005
Hi,
I got the VB6 code from this link.
http://www.a1vbcode.com/app-2790.asp
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.
Thanks for your support.
Thanks and Regards,
V.Chock.
Re: [2005] How to change Short Date format in system using VB.Net2005
If you're passing the AddressOf a method to an unmanaged function then you need to declare the argument as a delegate type, not an Integer.
'As Any' implies the type can be anything. Given that everything is derived from Object in .NET, you should change the declaration to 'As Object'.
Re: [2005] How to change Short Date format in system using VB.Net2005
Hi,
I tried as you said. But still its not working. Could you please try with the existing project and send it.
Thanks for your support,
V.Chock.
Re: [2005] How to change Short Date format in system using VB.Net2005
I very rarely download other people's projects and then only if it is necessary. In this case it isn't necessary. All you need to do is post the code directly into the thread so we can see it. We just need the API function declaration and where you're calling it.
Re: [2005] How to change Short Date format in system using VB.Net2005
Hi,
The below is the code in the module named modTime
Code:
'Option Strict Off
'Option Explicit On
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Module modTime
Public Const LOCALE_SLANGUAGE As Integer = &H2s
Public Const LOCALE_SSHORTDATE As Integer = &H1Fs
Public Const DATE_LONGDATE As Integer = &H2s
Public Const DATE_SHORTDATE As Integer = &H1s
Public Const HWND_BROADCAST As Integer = &HFFFF
Public Const WM_SETTINGCHANGE As Integer = &H1As
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByRef hwnd As Integer, ByRef wMsg As Integer, ByRef wParam As Integer, ByRef lParam As Object) As Integer
Public Delegate Function EnumDateFormats Lib "kernel32" Alias "EnumDateFormatsA" (ByRef lpDateFmtEnumProc As Integer, ByRef Locale As Integer, ByRef dwFlags As Integer) As Integer
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Object, ByRef Source As Object, ByVal Length As Integer)
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Integer
Public Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByRef Locale As Integer, ByRef LCType As Integer, ByRef lpLCData As String, ByRef cchData As Integer) As Integer
Public Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByRef Locale As Integer, ByRef LCType As Integer, ByRef lpLCData As String) As Integer
Public Function fGetUserLocaleInfo(ByRef lLocaleID As Integer, ByRef lLCType As Integer) As String
Dim sReturn As String
Dim lReturn As Integer
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
Return lReturn
End Function
Public Function theEnumDatesDelegate(ByRef lDateFormatString As Integer) As Integer
theEnumDatesDelegate = 1
End Function
Private Function GetStrFromPointer(ByRef sString As Integer) As String
Dim lPos As Integer
Dim sBuffer As String
sBuffer = Space(128)
Call CopyMemory(sBuffer, sString, Len(sBuffer))
lPos = InStr(sBuffer, Chr(0))
If lPos Then
GetStrFromPointer = Left(sBuffer, lPos - 1)
End If
End Function
End Module
The below is the code in the Form's Command Button, when the user press it the date format should be changed in regional settings
Code:
Option Strict Off
Option Explicit On
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Dim xCID As Integer
Dim xChangedFormat As String
xCID = GetSystemDefaultLCID()
xChangedFormat = "MM/dd/yyyy"
If xChangedFormat <> "" Then
Call SetLocaleInfo(xCID, LOCALE_SSHORTDATE, xChangedFormat)
Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
'UPGRADE_WARNING: Add a delegate for AddressOf theEnumDates Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
Call EnumDateFormats(AddressOf theEnumDatesDelegate, xCID, DATE_SHORTDATE)
End If
End Sub
Thanks for your support.
Thanks,
V.Chock.
Re: [2005] How to change Short Date format in system using VB.Net2005
What does this mean, EXACTLY?
Re: [2005] How to change Short Date format in system using VB.Net2005
Thanks For Your Support. Its working fine.
Thanks,
V.Chock.