CodeItBetter Programming Another VB Programming Blog

How to get User’s local information

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'System & API - How to get User's local information

'The following code will get the user local language, country, currency symbol, long date format,
'Long day's format, short day's format.

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
 
Private Sub Main()
    Dim buffer As String * 100
    Dim dl&
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, buffer, 99)
    Debug.Print " Language: " & LPSTRToVBString(buffer)
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGCOUNTRY, buffer, 99)
    Debug.Print " Country: " & LPSTRToVBString(buffer)
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, buffer, 99)
    Debug.Print " Currency Symbol: " & LPSTRToVBString(buffer)
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, buffer, 99)
    Debug.Print " Long date format: " & LPSTRToVBString(buffer)
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDAYNAME3, buffer, 99)
    Debug.Print " Long name for Wednesday: " & LPSTRToVBString(buffer)
    dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME3, buffer, 99)
    Debug.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
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.