Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11107

Re: SetLocale and automatic conversion

From "Ruediger Roesler" <worm.composter@nospam.arcornews.de>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: SetLocale and automatic conversion
Date 2015-07-11 17:17 +0200
Organization No Such Agency
Message-ID <d0cqj6Fc8liU1@mid.individual.net> (permalink)
References <55a11266$0$2946$e4fe514c@news2.news.xs4all.nl>

Show all headers | View raw


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.

-- 
ЯR

Back to microsoft.public.scripting.vbscript | Previous | NextNext in thread | Find similar


Thread

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