Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regional settings VIA Vb6

Status
Not open for further replies.

crisedefoie

Programmer
Feb 19, 2003
39
0
0
CA
Hi,

I'd like to know how to get the regionals settings of a computer via vb6. (specificaly for Date)

I have many users who use different settings and I need to know what theirs to show the right format on the screen.

Thanks for help.
 
Are you using the format function to show dates? If so, you can use "Short Date", "Long Date", and "Medium Date" to display a date using their regional settings.

For example...

Code:
Private Sub Command1_Click()

Debug.Print Format(Date, "Short Date")
Debug.Print Format(Date, "Medium Date")
Debug.Print Format(Date, "Long Date")

End Sub

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for answer,

I realized I was not clear et enough;

I forgot to tell that I have problems with DateTimePickers.

A datetimepicker returns its value on Regional Settings Date Format even if the format string is different.

So, when I want to use the datetimepicker.value in my own function it doesn't very well. If I would get Regional Settings of the user's environment, I'll change my functions, so my application would work well.
 
Hi crisedefoie

Try this API

Code:
Option Explicit

Const LOCALE_SLANGUAGE As Long = &H2
Const LOCALE_SENGLANGUAGE As Long = &H1001

Private Declare Function GetThreadLocale Lib "kernel32" () As Long

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


Public 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 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


Private Sub Command1_Click()

   Dim LCID As Long
    
   LCID = GetSystemDefaultLCID()
   
   'localized name of language
   Text1.Text = GetUserLocaleInfo(LCID, LOCALE_SLANGUAGE)
   
  'English name of language
   Text2.Text = GetUserLocaleInfo(LCID, LOCALE_SENGLANGUAGE)
    
  
End Sub

HTH
 
Hi LFC8 thanks for taking your time to helping me.

I got your code and changed the constant to get the short date format.

But, any format I set on my computer, it ALWAYS gives me the
dd/mm/yyyy format :¨-(

Even the long date format is wrong when I want to get it!

 
Hi

I'm not sure if this is what you need but you can format the date like this

Code:
Text3.Text = Format(Now, "mm/dd/yy")

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top