Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #11113
| Path | csiph.com!aioe.org!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Todd Vargo <tlvargo@sbcglobal.netz> |
| Newsgroups | microsoft.public.scripting.vbscript |
| Subject | Re: SetLocale and automatic conversion |
| Date | Sat, 11 Jul 2015 14:26:55 -0400 |
| Organization | albasani.net |
| Lines | 84 |
| Message-ID | <mnrn5d$ijp$1@news.albasani.net> (permalink) |
| References | <55a11266$0$2946$e4fe514c@news2.news.xs4all.nl> <d0cqj6Fc8liU1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net HdK+Jxr5w3y9HYLuYVBQCch9eVUdFNHr+RzK4p1MbU+ci1fp3sQ/qFyKaWmXWku1qNm5VYoCprWPviK//ngXsb1jqbMRZPb6oxQDhNNrrzioEbGBv69+HIU4xm8Q+vWF |
| NNTP-Posting-Date | Sat, 11 Jul 2015 18:26:53 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="JtY0w/3hOTFVI4z2o1D6KZtGuPx8l5QTctJcK6OnWDgmCfqQk3au3rhohEwU5Z10B8ddet5QYCxbq5Mt2ANSghJ3SS5EzQIJSQqfTCKbWqUkCmCMiIIjwxTZGdStHs9r"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| In-Reply-To | <d0cqj6Fc8liU1@mid.individual.net> |
| Cancel-Lock | sha1:VBLEnjX5lAEpIfJeeFa3UtoF+G0= |
| Xref | aioe.org microsoft.public.scripting.vbscript:11113 |
Show key headers only | View raw
On 7/11/2015 11:17 AM, Ruediger Roesler wrote:
> R.Wieser <address@not.available> typed:
>
>> I'm reading values outof a file, and ran into troubles because the
>> decimal-point notation was different of that of my local settings
>> (Europe uses "," where the USA uses ".").
>>
>> After some google-digging I found the SetLocal() command, and it works
>> well-ish.
>>
>> The problem is that it only seems to affect other commands (like
>> CDbl() ), but *not* any automatic conversion (which is a "disaster"
>> waiting to happen). :-|
>>
>> Example:
>> "3.4" + 1 => 35 (the dot is simply "forgotten")
>> CDbl("3.4") + 1 => 4,4
>>
>> Question:
>> How do get the automatic conversions to honour the
>> localisation-setting too ?
>>
>> Further info:
>> I've embedded a scripting-object into a program of mine, so I've got
>> quite a bit of access to all its objects. I've already been playing
>> with the GetLCID command (returning different LCIDs), but can't seem
>> to evoke any changed response.
>
> The GetLocale and SetLocale functions refers only to In- and Output.
> This little code example should explain that closer:
>
> '############################ Add1.vbs ################################
> For Each str In WSH.Arguments
> WSH.Echo
> For Each i In Array("de-de", "en-us", "en-gb", "nl-nl", "fr-fr")
> SetLocale(i)
> If IsNumeric(str) Then
> WSH.Echo i & ": " & CDbl(str) & " + 1 = " & CDbl(str) + 1
> Else
> WSH.Echo "Is not a numeric value in " & i & ": " & str
> End If
> Next
> Next
> '############################ Add1.vbs ################################
>
> If you run it on the command line, the result is:
>
> C:\>Add1 3,4 3.4
>
> de-de: 3,4 + 1 = 4,4
> en-us: 34 + 1 = 35
> en-gb: 34 + 1 = 35
> nl-nl: 3,4 + 1 = 4,4
> fr-fr: 3,4 + 1 = 4,4
>
> de-de: 34 + 1 = 35
> en-us: 3.4 + 1 = 4.4
> en-gb: 3.4 + 1 = 4.4
> nl-nl: 34 + 1 = 35
> Is not a numeric value in fr-fr: 3.4
>
> For writing code in VBScript you have to use the syntax of VBScript. :-)
> And a variable of the type double is always written with a decimal point.
>
C:\>Add1 3,400 3.400
de-de: 3,4 + 1 = 4,4
en-us: 3400 + 1 = 3401
en-gb: 3400 + 1 = 3401
nl-nl: 3,4 + 1 = 4,4
fr-fr: 3,4 + 1 = 4,4
de-de: 3400 + 1 = 3401
en-us: 3.4 + 1 = 4.4
en-gb: 3.4 + 1 = 4.4
nl-nl: 3400 + 1 = 3401
Is not a numeric value in fr-fr: 3.400
So this basically proves Garbage in Garbage out.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Back to microsoft.public.scripting.vbscript | Previous | Next — Previous in thread | Find similar
Re: SetLocale and automatic conversion "Ruediger Roesler" <worm.composter@nospam.arcornews.de> - 2015-07-11 17:17 +0200
Re: SetLocale and automatic conversion "R.Wieser" <address@not.available> - 2015-07-11 17:28 +0200
Re: SetLocale and automatic conversion "Ruediger Roesler" <worm.composter@nospam.arcornews.de> - 2015-07-11 19:11 +0200
Re: SetLocale and automatic conversion "R.Wieser" <address@not.available> - 2015-07-11 20:17 +0200
Re: SetLocale and automatic conversion Todd Vargo <tlvargo@sbcglobal.netz> - 2015-07-11 14:26 -0400
csiph-web