VB6, Locale and the Windows API

I want my VB6 application (.exe) to set the locale (for the current process) to "en-US" if it detects that the default locale's decimal point is not a dot ".".

How do I find out what the current decimal separator character is in VB6 using the Windows API?

How can I change the current process's locale to "en-US" in VB6 using the Windows API?

I need to do this on Windows 7 or later.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
What code is involved with the decimal point. I ask because some methods are locale-aware and others aren't. Here's an article on the subject.
ou81aswellAuthor Commented:
This is a legacy app with lots of potential for locale problems as it generates SQL internally and on-the-fly all over the place.

Literal values expressed using the current locale are screwing up the SQL parser which is expecting the English use of dots and commas.

I am aware of the use of str() to get around this but there are too many places to visit and I'm not sure it's worth the time and risk.

One user has gotten into the habit of changing his Windows Region parameters for decimal and thousands separators so the software works but he keeps forgetting to change them back after exiting, causing trouble in other applications..
Martin LissOlder than dirtCommented:
You could have the app do it automatically. I'm sure that if you look for it that you'll find existing code that does it.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

[ fanpages ]IT Services ConsultantCommented:
How do I find out what the current decimal separator character is in VB6 using the Windows API?

Option Explicit

Declare Function GetLocaleInfo _
             Lib "kernel32.dll" _
           Alias "GetLocaleInfoA" _
          (ByVal Locale As Long, _
           ByVal LCType As Long, _
           ByVal lpLCData As String, _
           ByVal cchData As Long) As Long

Declare Function GetUserDefaultLCID _
             Lib "kernel32.dll" _
                 () As Integer
Public Sub Get_Decimal_Separator()

  Dim intPos                                            As Integer
  Dim lngLocale                                         As Long
  Dim lngReturn1                                        As Long
  Dim lngReturn2                                        As Long
  Dim strSymbol                                         As String
  Dim strlpLCDataVar                                    As String

  Const lngLOCALE_SMONDECIMALSEP                        As Long = &H16
  lngLocale = GetUserDefaultLCID()
  lngReturn1 = GetLocaleInfo(lngLocale, lngLOCALE_SMONDECIMALSEP, strlpLCDataVar, 0&)
  strSymbol = String$(lngReturn1, 0)
  lngReturn2 = GetLocaleInfo(lngLocale, lngLOCALE_SMONDECIMALSEP, strSymbol, lngReturn1)
  intPos = InStr(strSymbol, Chr$(0))
  If intPos > 0 Then
     strSymbol = Left$(strSymbol, intPos - 1)
     MsgBox "The Decimal Separator is " & strSymbol, _
            vbInformation Or vbOKOnly
  End If ' If intPos > 0 Then

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dim sep As String
sep = Mid$(1.5, 2, 1)
MsgBox "The Decimal Separator is " & sep

Open in new window

ou81aswellAuthor Commented:
I used Ark's Mid() approach because of its simplicity, even though my code already calls GetLocaleInfo to get the system's short-date format.

Additionally, it turns out that there's a bug in ADO's UpdateBatch function involving decimal column types. The operation fails if the system decimal separator is not a dot. This was the root cause of the problem. I was able to work around it by using Double data types instead of Decimal.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.