Is it possible? I thought that it would be necessary to do that through regional settings. But then it seems the regisry is used for most things today!
Declare Function SetLocaleInfo Lib \"kernel32\" Alias \"SetLocaleInfoA\" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
Private Declare Function GetThreadLocale Lib \"kernel32\" () As Long
Private Const LOCALE_SSHORTDATE = &H1F
\'LOCALE_SSHORTDATE \'Short date formatting string for this locale. The string can consist of a combination of day, month, and year format pictures defined in Day, Month, Year, and Era Format Pictures table in National Language Support Constants. The maximum number of characters allowed for this string is 80.
Du kan sætte det ind i et class module som properties
Public Property Get ShortDateFormat() As String \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next Buffer = String(GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, Buffer, 0), \" \") Fetched = GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, Buffer, Len(Buffer)) If Fetched > 0 Then ShortDateFormat = Mid(Buffer, 1, Fetched - 1) End Property Public Property Let ShortDateFormat(ByVal sFormat as String) \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, sFormat, Len(sFormat)) End Property
Jeg har lavet en classmodule der hedder \"clsDatoHåndtering\" og har min hovedform der hedder \"frmCVM\" som programmet starter med så...
Hvor skal 1) og 2) sidde i min kode
1) Declare Function SetLocaleInfo Lib \"kernel32\" Alias \"SetLocaleInfoA\" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
Private Declare Function GetThreadLocale Lib \"kernel32\" () As Long
Private Const LOCALE_SSHORTDATE = &H1F
2) Public Property Get ShortDateFormat() As String \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next Buffer = String(GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, Buffer, 0), \" \") Fetched = GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, Buffer, Len(Buffer)) If Fetched > 0 Then ShortDateFormat = Mid(Buffer, 1, Fetched - 1) End Property Public Property Let ShortDateFormat(ByVal sFormat as String) \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, sFormat, Len(sFormat)) End Property
når jeg sætter et breakpoint i koden og \"følger\" med køres kun igennem...
Public Property Let ShortDateFormat(ByVal sFormat As String) \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next SetLocaleInfo GetThreadLocale, LOCALE_SSHORTDATE, sFormat End Property
...Er det rigtigt??
Hvad skal ...
Public Property Get ShortDateFormat() As String \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next buffer = String(GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, buffer, 0), \" \") Fetched = GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, buffer, Len(buffer)) If Fetched > 0 Then ShortDateFormat = Mid(buffer, 1, Fetched - 1) End Property
...så bruges til??
>> Benny - hvis du stadig er der så hjælp mig lige færdig. Kan du købes ;-) ;-)
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
i clsDatoFormat sammen med den anden Declare function
OK - så får jeg det aktuelle datoformat tilbage, men jeg kan stadig ikke ændre det. ER der noget galt med...
Public Property Let ShortDateFormat(ByVal sFormat As String) \'used when retrieving value of a property, on the right side of an assignment. \'Syntax: Debug.Print X.ShortDateFormat On Error Resume Next Call SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, sFormat & Chr$(0)) \'MsgBox sFormat & Chr$(0)
End Property
...Hvorfor skal der ikke sendes en parameter med over fra ...
Ifølge MS Platform SDK, så skal d\'erne være med småt, M\'erne med stort og y\'erne med småt.
Jeg prøvede lige på min:
Opret et projekt, standard exe.
På form1 indsættes en listbox (bibehold navnet List1).
I kodeview indsættes følgende:
Option Explicit
Dim cCPL As clsControlPanel
Private Sub Form_Load() Set cCPL = New clsControlPanel With List1 .Clear .AddItem \"dd-MM-yy\" .AddItem \"dd-MM-yyyy\" .AddItem \"MM-dd-yy\" .AddItem \"MM-dd-yyyy\" .AddItem \"yy-MM-dd\" .AddItem \"yyyy-MM-dd\" End With End Sub
Private Sub Form_Unload(Cancel As Integer) Set cCPL = Nothing End Sub
Private Sub List1_Click() If List1.ListIndex < 0 Then Exit Sub cCPL.ShortDateFormat = List1.List(List1.ListIndex) Me.Caption = cCPL.ShortDateFormat End Sub
Tilføj et Class modul, navngiv det clsControlPanel
I code view indsætter du følgende:
Option Explicit
Private Const LOCALE_SSHORTDATE = &H1F
Private Declare Function GetThreadLocale Lib \"kernel32\" () As Long 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 SetLocaleInfo Lib \"kernel32\" Alias \"SetLocaleInfoA\" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
Private sBuffer As String Private lFetched As Long Private lNeedLen As Long
Public Property Get ShortDateFormat() As String lNeedLen = GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, sBuffer, 0) sBuffer = String$(lNeedLen, 0) lFetched = GetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, sBuffer, Len(sBuffer)) ShortDateFormat = Left$(sBuffer, lFetched - 1) End Property Public Property Let ShortDateFormat(sFormat As String) SetLocaleInfo GetThreadLocale, LOCALE_SSHORTDATE, sFormat & Chr$(0) End Property
Køres programmet, vil datoformatet blive sat til det format, du vælger i listboxen. Det virker i min - og Windows registrerer ændringen i kontrolpanelets regionale indstillinger. Var denne åben på skiftetidspunktet, ændres det først efter en nedlukning af regionale indstillinger.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.