There are two issues at play here. I will illustrate using two locales:
English (Canada) -- EN-CA: which uses .
as the decimal separator
French (Canada) -- FR-CA: which uses ,
as the decimal separator
and tiny bits of VBScript code (as I don't have C++).
Issue 1: Conversion of decimal numbers to/from locale-aware strings.
The VBScript
x = 3/2
WScript.Echo x
displays 1.5
when the Windows locale is EN-CA, and it displays 1,5
when the Windows locale is FR-CA. That text is what you are seeing in your edit box.
Say the user leaves the string unchanged. Instead of trying to use the string representation of the decimal number you need to use a locale-aware method of converting the string back to an actual decimal number:
For EN-CA:
x = CDbl("1.5") + 1
WScript.Echo x
displays 2.5
indicating that the string "1.5" was successfully converted to a Double
before adding 1.
For FR-CA:
x = CDbl("1,5") + 1
WScript.Echo x
displays 2,5
indicating that the string "1,5" was successfully converted to a Double
before adding 1.
Summary: When you receive a text representation of a number from the user you need to convert (i.e., parse) that string to an actual numeric data type, and the parsing mechanism must be locale-aware.
Issue 2: Storing the number in the database.
The problem here is that Access SQL is not locale-aware; it only "speaks" US English. So if you try and "glue together" a SQL command under FR-CA
x = 3/2
sql = "INSERT INTO Table1 (DoubleField) VALUES (" & x & ")"
WScript.Echo sql
you get INSERT INTO Table1 (DoubleField) VALUES (1,5)
and that fails, as you have discovered.
The solution here is to NOT "glue together" SQL commands (which is a Bad Thing anyway, because of SQL Injection vulnerabilities and other nuisances). Instead, use a parameterized query:
Option Explicit
Dim con ' ADODB.Connection
Dim cmd ' ADODB.Command
Dim prm ' ADODB.Parameter
Dim x
Const adDouble = 5
Const adParamInput = 1
' test data:
' the following statement is valid when
' the Windows locale uses "," as the decimal separator
x = CDbl("1,5")
Set con = CreateObject("ADODB.Connection")
con.Open _
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" & _
"Dbq=C:\__tmp\main.accdb;"
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandText = "INSERT INTO Table1 (DoubleField) VALUES (?)"
Set prm = cmd.CreateParameter("?", adDouble, adParamInput, , x)
cmd.Parameters.Append prm
cmd.Execute
Set prm = Nothing
Set cmd = Nothing
con.Close
Set con = Nothing