CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Posts
    14

    regional settings date format

    How to change the date format in the regional settings to dd/mm/yyyy as and when my application(in vb) loads?


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: regional settings date format

    Private Const LOCALE_SLONGDATE As Long = &H20 'long date format string

    Private Declare Function GetSystemDefaultLCID 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 Sub Command1_Click()

    MsgBox GetLongDateFormat

    End Sub


    Private Function GetLongDateFormat() As String

    Dim LCID As Long

    'get the locale for the user
    LCID = GetSystemDefaultLCID()

    If LCID <> 0 Then

    'return the long date format
    GetLongDateFormat = GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)

    End If

    End Function


    Private Function GetUserLocaleInfo(ByVal dwLocaleID As Long, ByVal dwLCType As Long) As String

    Dim sReturn As String
    Dim r As Long

    'call the function passing the Locale type
    'variable to retrieve the required size of
    'the string buffer needed
    r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

    'if successful..
    If r Then

    'pad the buffer with r spaces
    sReturn = Space$(r)

    'and call again passing the buffer
    r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))

    'if successful (r > 0)
    If r Then

    'r holds the size of the string
    'including the terminating null
    GetUserLocaleInfo = Left$(sReturn, r - 1)

    End If

    End If

    End Function



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured