vwiley1
Jun 22nd, 2000, 12:44 PM
Hi,
I'm Vince. I'm developing a small application in MS Access for a German client. In India we use "." for decimal places and "," for group separators. But in Germany it is different like they use "," for decimal places and "." for group separators. we have coded the application, without taking German practice into the consideration. Now the problem comes when the client started using the application and entering the decimal places. The application is saving the numbers " 0.66" as "66" and "1.66" as "166". That is it is not considering the "." as decimal. But the client now want to enter only "." as decimal but want to see "," in place of decimal i.e. he will enter "1.66" and want to see as "1,66" on the front end. While doing so, the regional settings need to be changed, for which client is not ready. Can you please tell me how can I solve this problem without changing his regional setings (numbers). If changing regional settings is the only solution, how can I do that using API calls? And at the closing of the application, his old regional settings should be back.
I don't think changin the local settings would be an option because this would also change the settings for any other program he might be useing.
You could read his settings and then convert his data.
Here is an example:
Add a listview called ListView1 to a form
And add a class called CLocale to your project
Copy the following code in form1
Option Explicit
Private Sub Form_Load()
Dim CLocale As CLocale
Dim xLI As ListItem
Set CLocale = New CLocale
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Name"
ListView1.ColumnHeaders.Add , , "Value"
CLocale.ReadSettings [System Default Locale]
Set xLI = ListView1.ListItems.Add(, , "SYSTEM SETTINGS")
xLI.SubItems(1) = "SYSTEM SETTINGS"
Set xLI = ListView1.ListItems.Add(, , "")
Read CLocale
Set xLI = ListView1.ListItems.Add(, , "")
CLocale.ReadSettings [User Default Locale]
Set xLI = ListView1.ListItems.Add(, , "USER SETTINGS")
xLI.SubItems(1) = "USER SETTINGS"
Read CLocale
Set CLocale = Nothing
End Sub
Private Sub Read(ByVal CLocale As CLocale)
Dim xLI As ListItem
Set xLI = ListView1.ListItems.Add(, , "DateSeparator")
xLI.SubItems(1) = CLocale.DateSeparator
Set xLI = ListView1.ListItems.Add(, , "TimeSeparator")
xLI.SubItems(1) = CLocale.TimeSeparator
Set xLI = ListView1.ListItems.Add(, , "Short Date")
xLI.SubItems(1) = CLocale.DateFormatShort
Set xLI = ListView1.ListItems.Add(, , "Long Date")
xLI.SubItems(1) = CLocale.DateFormatLong
Set xLI = ListView1.ListItems.Add(, , "Time Format")
xLI.SubItems(1) = CLocale.TimeFormat
Set xLI = ListView1.ListItems.Add(, , "DecimalSepartor")
xLI.SubItems(1) = CLocale.DecimalSeparator
Set xLI = ListView1.ListItems.Add(, , "ThousandSepartor")
xLI.SubItems(1) = CLocale.ThousandSeparator
Set xLI = ListView1.ListItems.Add(, , "EnglishCountryName")
xLI.SubItems(1) = CLocale.EnglishCountryName
Set xLI = ListView1.ListItems.Add(, , "LocalCountryName")
xLI.SubItems(1) = CLocale.LocalCountryName
Set xLI = ListView1.ListItems.Add(, , "CountryCode")
xLI.SubItems(1) = CLocale.CountryCode
Set xLI = ListView1.ListItems.Add(, , "DefaultLanguage")
xLI.SubItems(1) = CLocale.DefaultLanguage
Set xLI = ListView1.ListItems.Add(, , "MetricSystem")
Select Case CLocale.MetricSystem
Case [S.I. Metric system]
xLI.SubItems(1) = "[S.I. Metric system]"
Case [U.S. Metric system]
xLI.SubItems(1) = "[U.S. Metric system]"
'End Case
End Select
Set xLI = ListView1.ListItems.Add(, , "MonetarySymbol")
xLI.SubItems(1) = CLocale.MonetarySymbol
End Sub
And add the following code to the class named CLocale
Option Explicit
Private Declare Function GetThreadLocale Lib "kernel32" () As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetUserDefaultLCID 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
Private Const LOCALE_ILANGUAGE As Long = &H1 'language id
Private Const LOCALE_SLANGUAGE As Long = &H2 'localized name of language
Private Const LOCALE_SENGLANGUAGE As Long = &H1001 'English name of language
Private Const LOCALE_SABBREVLANGNAME As Long = &H3 'abbreviated language name
Private Const LOCALE_SNATIVELANGNAME As Long = &H4 'native name of language
Private Const LOCALE_ICOUNTRY As Long = &H5 'country code
Private Const LOCALE_SCOUNTRY As Long = &H6 'localized name of country
Private Const LOCALE_SENGCOUNTRY As Long = &H1002 'English name of country
Private Const LOCALE_SABBREVCTRYNAME As Long = &H7 'abbreviated country name
Private Const LOCALE_SNATIVECTRYNAME As Long = &H8 'native name of country
Private Const LOCALE_SINTLSYMBOL As Long = &H15 'intl monetary symbol
Private Const LOCALE_IDEFAULTLANGUAGE As Long = &H9 'default language id
Private Const LOCALE_IDEFAULTCOUNTRY As Long = &HA 'default country code
Private Const LOCALE_IDEFAULTCODEPAGE As Long = &HB 'default oem code page
Private Const LOCALE_IDEFAULTANSICODEPAGE As Long = &H1004 'default ansi code page
Private Const LOCALE_IDEFAULTMACCODEPAGE As Long = &H1011 'default mac code page
Private Const LOCALE_IMEASURE As Long = &HD '0 = metric, 1 = US
Private Const LOCALE_SISO639LANGNAME As Long = &H59 'ISO abbreviated language name
Private Const LOCALE_SISO3166CTRYNAME As Long = &H5A 'ISO abbreviated country name
Private Const LOCALE_SNATIVECURRNAME As Long = &H1008 'native name of currency
Private Const LOCALE_IDEFAULTEBCDICCODEPAGE As Long = &H1012 'default ebcdic code page
Private Const LOCALE_SSORTNAME As Long = &H1013 'sort name
Private Const LOCALE_SCURRENCY As Long = &H14 'local monetary symbol
Private Const LOCALE_SMONDECIMALSEP As Long = &H16 'monetary decimal separator
Private Const LOCALE_SMONTHOUSANDSEP As Long = &H17 'monetary thousand separator
Private Const LOCALE_SMONGROUPING As Long = &H18 'monetary grouping
Private Const LOCALE_ICURRDIGITS As Long = &H19 '# local monetary digits
Private Const LOCALE_IINTLCURRDIGITS As Long = &H1A '# intl monetary digits
Private Const LOCALE_ICURRENCY As Long = &H1B 'positive currency mode
Private Const LOCALE_INEGCURR As Long = &H1C 'negative currency mode
Private Const LOCALE_IPOSSIGNPOSN As Long = &H52 'positive sign position
Private Const LOCALE_INEGSIGNPOSN As Long = &H53 'negative sign position
Private Const LOCALE_IPOSSYMPRECEDES As Long = &H54 'mon sym precedes pos amt
Private Const LOCALE_IPOSSEPBYSPACE As Long = &H55 'mon sym sep by space from pos amt
Private Const LOCALE_INEGSYMPRECEDES As Long = &H56 'mon sym precedes neg amt
Private Const LOCALE_INEGSEPBYSPACE As Long = &H57 'mon sym sep by space from neg amt
Private Const LOCALE_SENGCURRNAME As Long = &H1007 'english name of currency
Private Const LOCALE_SDECIMAL As Long = &HE 'decimal separator
Private Const LOCALE_STHOUSAND As Long = &HF 'thousand separator
Private Const LOCALE_SGROUPING As Long = &H10 'digit grouping
Private Const LOCALE_IDIGITS As Long = &H11 'number of fractional digits
Private Const LOCALE_ILZERO As Long = &H12 'leading zeros for decimal
Private Const LOCALE_INEGNUMBER As Long = &H1010 'negative number mode
Private Const LOCALE_SNATIVEDIGITS As Long = &H13 'native ascii 0-9
Private Const LOCALE_SPOSITIVESIGN As Long = &H50 'positive sign
Private Const LOCALE_SNEGATIVESIGN As Long = &H51 'negative sign
Private Const LOCALE_STIME As Long = &H1E 'time separator
Private Const LOCALE_SDATE As Long = &H1D 'date separator
Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format string
Private Const LOCALE_SLONGDATE As Long = &H20 'long date format string
Private Const LOCALE_STIMEFORMAT As Long = &H1003 'time format string
'===
'LOCALE_ICALENDARTYPE 'The type of calendar currently in use. [2]
'1 Gregorian (as in U.S.)
'2 Gregorian (always English strings)
'3 Era: Year of the Emperor (Japan)
'4 Era: Year of the Taiwan Region
'5 Tangun Era(Korea)
'LOCALE_SDATE Characters used for the date separator.
'LOCALE_STIME Characters used for the time separator.
'LOCALE_STIMEFORMAT Time-formatting string. [80]
Private msDecimalSeparator As String
Private msThousandSeparator As String
Private msCountryCode As String
Private msDefaultLanguage As String
Private msLocalCountryName As String
Private msEnglishCountryName As String
Private msMonetarySymbol As String
Private msDateSeparator As String
Private msTimeSeparator As String
Private msDateFormatShort As String
Private msDateFormatLong As String
Private msTimeFormat As String
Private meMetricSystem As enMetricSystem
Public Enum enMetricSystem
[S.I. Metric system] = 0
[U.S. Metric system] = 1
End Enum
Public Enum enLocale
[System Default Locale] = 0
[User Default Locale] = 1
End Enum
Private 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
Public Property Get DateFormatLong() As String
DateFormatLong = msDateFormatLong
End Property
Private Property Let DateFormatLong(sDateFormatLong As String)
msDateFormatLong = sDateFormatLong
End Property
Public Property Get DateFormatShort() As String
DateFormatShort = msDateFormatShort
End Property
Private Property Let DateFormatShort(sDateFormatShort As String)
msDateFormatShort = sDateFormatShort
End Property
Public Property Get TimeFormat() As String
TimeFormat = msTimeFormat
End Property
Private Property Let TimeFormat(sTimeFormat As String)
msTimeFormat = sTimeFormat
End Property
Public Property Get MonetarySymbol() As String
MonetarySymbol = msMonetarySymbol
End Property
Private Property Let MonetarySymbol(sMonetarySymbol As String)
msMonetarySymbol = sMonetarySymbol
End Property
Public Property Get DateSeparator() As String
DateSeparator = msDateSeparator
End Property
Private Property Let DateSeparator(sDateSeparator As String)
msDateSeparator = sDateSeparator
End Property
Public Property Get TimeSeparator() As String
TimeSeparator = msTimeSeparator
End Property
Private Property Let TimeSeparator(sTimeSeparator As String)
msTimeSeparator = sTimeSeparator
End Property
Public Property Get EnglishCountryName() As String
EnglishCountryName = msEnglishCountryName
End Property
Private Property Let EnglishCountryName(sEnglishCountryName As String)
msEnglishCountryName = sEnglishCountryName
End Property
Public Property Get LocalCountryName() As String
LocalCountryName = msLocalCountryName
End Property
Private Property Let LocalCountryName(sLocalCountryName As String)
msLocalCountryName = sLocalCountryName
End Property
Public Property Get DecimalSeparator() As String
DecimalSeparator = msDecimalSeparator
End Property
Private Property Let CountryCode(sCountryCode As String)
msCountryCode = sCountryCode
End Property
Public Property Get CountryCode() As String
CountryCode = msCountryCode
End Property
Private Property Let DecimalSeparator(sDecimalSeparator As String)
msDecimalSeparator = sDecimalSeparator
End Property
Public Property Get ThousandSeparator() As String
ThousandSeparator = msThousandSeparator
End Property
Private Property Let ThousandSeparator(sThousandSeparator As String)
msThousandSeparator = sThousandSeparator
End Property
Public Property Get DefaultLanguage() As String
DefaultLanguage = msDefaultLanguage
End Property
Private Property Let DefaultLanguage(sDefaultLanguage As String)
msDefaultLanguage = sDefaultLanguage
End Property
Private Property Let MetricSystem(eMetricSystem As enMetricSystem)
meMetricSystem = eMetricSystem
End Property
Public Property Get MetricSystem() As enMetricSystem
MetricSystem = meMetricSystem
End Property
Public Sub ReadSettings(ByVal SorU As enLocale)
Dim LCID As Long
Select Case SorU
Case enLocale.[System Default Locale]
LCID = GetSystemDefaultLCID()
Case enLocale.[User Default Locale]
LCID = GetUserDefaultLCID()
'End Case
End Select
DateSeparator = GetUserLocaleInfo(LCID, LOCALE_SDATE)
TimeSeparator = GetUserLocaleInfo(LCID, LOCALE_STIME)
DateFormatLong = GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)
DateFormatShort = GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)
TimeFormat = GetUserLocaleInfo(LCID, LOCALE_STIMEFORMAT)
DecimalSeparator = GetUserLocaleInfo(LCID, LOCALE_SDECIMAL)
ThousandSeparator = GetUserLocaleInfo(LCID, LOCALE_STHOUSAND)
CountryCode = GetUserLocaleInfo(LCID, LOCALE_ICOUNTRY)
DefaultLanguage = GetUserLocaleInfo(LCID, LOCALE_IDEFAULTLANGUAGE)
Select Case GetUserLocaleInfo(LCID, LOCALE_IMEASURE)
Case "0"
MetricSystem = [S.I. Metric system]
Case "1"
MetricSystem = [U.S. Metric system]
'End Case
End Select
LocalCountryName = GetUserLocaleInfo(LCID, LOCALE_SCOUNTRY)
EnglishCountryName = GetUserLocaleInfo(LCID, LOCALE_SENGCOUNTRY)
MonetarySymbol = GetUserLocaleInfo(LCID, LOCALE_SINTLSYMBOL)
End Sub
I know its kinda big, but i hope it helps.