-
Apr 22nd, 2004, 04:45 PM
#1
Thread Starter
New Member
Determining regional setting in VBA code
How do you do it?
In other words, at run-time, I want to determine the system regional settings and be able to test against the returned info.
Of course, using something like MonthName(1), it would give me either an English name for January, or the word in some other language. But there's got to be a better way...
Any suggestions?
-
Apr 22nd, 2004, 05:26 PM
#2
Thread Starter
New Member
Well, I found this code:
VB Code:
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 ReadLocaleInfo(ByVal lInfo As Long) As String Dim sBuffer As String Dim rv As String sBuffer = String$(256, 0) rv = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, sBuffer, Len(sBuffer)) If rv > 0 Then ReadLocaleInfo = Left$(sBuffer, rv - 1) Else 'MsgBox "Not found" ReadLocaleInfo = "" End If End Function
I've tried it with the following inputs:
VB Code:
MsgBox ("UserDefault: " & ReadLocaleInfo(LOCALE_USER_DEFAULT)) MsgBox ("SDecimal: " & ReadLocaleInfo(LOCALE_SDECIMAL)) MsgBox ("ILDate: " & ReadLocaleInfo(LOCALE_ILDATE)) MsgBox ("Country: " & ReadLocaleInfo(LOCALE_ICOUNTRY))
...and in each case, it returned an empty string.
Any ideas?
-
Apr 22nd, 2004, 05:54 PM
#3
I have this example from allapi.net which is where you may have
got the example from and they use different const.'s
This works for me but the UserDefault.
VB Code:
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 Private Sub Form_Load() MsgBox "You live in " & GetInfo(LOCALE_SENGCOUNTRY) & _ " (" & GetInfo(LOCALE_SNATIVECTRYNAME) & ")," & vbCrLf & "and 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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Star Wars Gangsta Rap • Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010 
-
Apr 22nd, 2004, 06:18 PM
#4
Thread Starter
New Member
Thanks for the response...
As it turns out, if I just use the hex codes, things work fine.
-
May 10th, 2004, 09:23 PM
#5
Fanatic Member
Application.International(xlCountrySetting)
this will return the regional country settings and you will be able to set your application accordingly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|