Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #11113
| From | Todd Vargo <tlvargo@sbcglobal.netz> |
|---|---|
| Newsgroups | microsoft.public.scripting.vbscript |
| Subject | Re: SetLocale and automatic conversion |
| Date | 2015-07-11 14:26 -0400 |
| Organization | albasani.net |
| Message-ID | <mnrn5d$ijp$1@news.albasani.net> (permalink) |
| References | <55a11266$0$2946$e4fe514c@news2.news.xs4all.nl> <d0cqj6Fc8liU1@mid.individual.net> |
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