- Local time
- Today, 01:51
- Joined
- Sep 12, 2006
- Messages
- 15,658
I had some date functions that didn't work properly because the user had changed the regional settings. Anyway, so here's a module with a couple of functions. Not mine - not sure where it came from now - not sure if something like this is already on AWF, but I havent seen it.
locale_UK (boolean to check we are in UK - region 44)
locale_string (string returning the actual region we are in)
locale_UK (boolean to check we are in UK - region 44)
locale_string (string returning the actual region we are in)
Code:
Option Compare Database
Option Explicit
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 Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SDECIMAL As Long = &HE
Private Const LOCALE_ILDATE As Long = &H22
Private Const LOCALE_ICOUNTRY As Long = &H5
Private Const LOCALE_SENGCOUNTRY = &H1002 ' English name of country
Private Const LOCALE_SENGLANGUAGE = &H1001 ' English name of language
Private Const LOCALE_SNATIVELANGNAME = &H4 ' native name of language
Private Const LOCALE_SNATIVECTRYNAME = &H8 ' native name of country
Public Function GetInfo(ByVal lInfo As Long) As String
Dim Buffer As String
Dim Ret As String
Buffer = String$(256, 0)
Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer))
If Ret > 0 Then
GetInfo = Left$(Buffer, Ret - 1)
Else
GetInfo = ""
End If
End Function
Function locale_UK() As Boolean
locale_UK = GetInfo(LOCALE_ICOUNTRY) = 44
End Function
Function locale_string() As String
locale_string = GetInfo(LOCALE_SENGCOUNTRY)
End Function
Private Sub Locale_Check()
'some other examples
'MsgBox "You live in " & GetInfo(LOCALE_SENGCOUNTRY) & _
'" (" & GetInfo(LOCALE_SNATIVECTRYNAME) & "), " & GetInfo(LOCALE_ICOUNTRY) & vbCrLf
'MsgBox "You live in " & GetInfo(LOCALE_SENGCOUNTRY) & _
'" (" & GetInfo(LOCALE_SNATIVECTRYNAME) & "), " & GetInfo(LOCALE_ICOUNTRY) & vbCrLf & _
'"You speak " & GetInfo(LOCALE_SENGLANGUAGE) & _
'" (" & GetInfo(LOCALE_SNATIVELANGNAME) & ").", vbInformation 'WORKS CORRECTLY
'MsgBox ("UserDefault: " & GetInfo(LOCALE_USER_DEFAULT)) 'STILL EMPTY STRING
'MsgBox ("SDecimal: " & GetInfo(LOCALE_SDECIMAL)) 'RETURNS "."
'MsgBox ("ILDate: " & GetInfo(LOCALE_ILDATE)) 'RETURNS "0"
'MsgBox ("Country: " & GetInfo(LOCALE_ICOUNTRY)) 'RETURNS "1"
End Sub