Make your own free website on Tripod.com

Get Useful User's Local Information

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 Command Button to your form.
'The program will get the user local language, country, currency symbol, long date format,
'Long day's format, short day's format.
'Insert the following code to your module:

Public Const LOCALE_USER_DEFAULT = &H400
Public Const LOCALE_SENGLANGUAGE = &H1001
Public Const LOCALE_SENGCOUNTRY = &H1002
Public Const LOCALE_SCURRENCY = &H14
Public Const LOCALE_SLONGDATE = &H20
Public Const LOCALE_SDAYNAME1 = &H2A 'long name for Monday
Public Const LOCALE_SDAYNAME2 = &H2B 'long name for Tuesday
Public Const LOCALE_SDAYNAME3 = &H2C 'long name for Wednesday
Public Const LOCALE_SDAYNAME4 = &H2D 'long name for Thursday
Public Const LOCALE_SDAYNAME5 = &H2E 'long name for Friday
Public Const LOCALE_SDAYNAME6 = &H2F 'long name for Saturday
Public Const LOCALE_SDAYNAME7 = &H30 'long name for Sunday
Public Const LOCALE_SABBREVDAYNAME1 = &H31 'short name for Monday
Public Const LOCALE_SABBREVDAYNAME2 = &H32 'short name for Tuesday
Public Const LOCALE_SABBREVDAYNAME3 = &H33 'short name for Wednesday
Public Const LOCALE_SABBREVDAYNAME4 = &H34 'short name for Thursday
Public Const LOCALE_SABBREVDAYNAME5 = &H35 'short name for Friday
Public Const LOCALE_SABBREVDAYNAME6 = &H36 'short name for Saturday
Public Const LOCALE_SABBREVDAYNAME7 = &H37 'short name for Sunday
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

'Insert the following code to your form:

Private Sub Command1_Click()
Dim buffer As String * 100
Dim dl&
Form1.Cls
dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, _
LOCALE_SENGLANGUAGE, buffer, 99)
Print " Language: " & LPSTRToVBString(buffer)
dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, _
LOCALE_SENGCOUNTRY, buffer, 99)
Print " Country: " & LPSTRToVBString(buffer)
dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, buffer, 99)
Print " Currency Symbol: " & LPSTRToVBString(buffer)
dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, buffer, 99)
Print " Long date format: " & LPSTRToVBString(buffer)
'Replace 'LOCALE_SDAYNAME3' with the constant of the day you want to see his
'long name. You can see all the constants in the module code above.

dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDAYNAME3, buffer, 99)
Print " Long name for Wednesday: " & LPSTRToVBString(buffer)
'Replace 'LOCALE_SABBREVDAYNAME3' with the constant of the day you want to see
'His short name.

dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, _
LOCALE_SABBREVDAYNAME3, buffer, 99)
Print " Abbreviation for Wednesday: " & LPSTRToVBString(buffer)
End Sub

Private Function LPSTRToVBString$(ByVal s$)
Dim nullpos&
nullpos& = InStr(s$, Chr$(0))
If nullpos > 0 Then
LPSTRToVBString = Left$(s$, nullpos - 1)
Else
LPSTRToVBString = ""
End If
End Function

Go Back