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


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

Re: SetLocale and automatic conversion

Started by"Ruediger Roesler" <worm.composter@nospam.arcornews.de>
First post2015-07-11 17:17 +0200
Last post2015-07-11 14:26 -0400
Articles 5 — 3 participants

Back to article view | Back to microsoft.public.scripting.vbscript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#11107 — Re: SetLocale and automatic conversion

From"Ruediger Roesler" <worm.composter@nospam.arcornews.de>
Date2015-07-11 17:17 +0200
SubjectRe: SetLocale and automatic conversion
Message-ID<d0cqj6Fc8liU1@mid.individual.net>
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

[toc] | [next] | [standalone]


#11108

From"R.Wieser" <address@not.available>
Date2015-07-11 17:28 +0200
Message-ID<55a13589$0$2842$e4fe514c@news2.news.xs4all.nl>
In reply to#11107
Ruediger,

> And a variable of the type double is always written
> with a decimal point.

I'm not at all sure if I understand you here, as the output of your own code
already shows otherwise ...

Regards,
Rudy Wieser


-- Origional message
Ruediger Roesler <worm.composter@nospam.arcornews.de> schreef in
berichtnieuws d0cqj6Fc8liU1@mid.individual.net...
> 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
>

[toc] | [prev] | [next] | [standalone]


#11111

From"Ruediger Roesler" <worm.composter@nospam.arcornews.de>
Date2015-07-11 19:11 +0200
Message-ID<d0d14lFdt6gU1@mid.individual.net>
In reply to#11108
R.Wieser <address@not.available> typed:

>> And a variable of the type double is always written
>> with a decimal point.
>
> I'm not at all sure if I understand you here, as the output of your
> own code already shows otherwise ...

Sorry, it did not.

Ok, it's a little bit confusing, I have expanded the code a little bit:

'############################ Add1.vbs ################################
For Each str In WSH.Arguments
    For Each i In Array("de-de", "en-us", "en-gb", "nl-nl", "fr-fr")
        SetLocale (i)
        WSH.Echo vbCRLF & "Calculate the value of " & str & " plus 1:"
        If IsNumeric(str) Then
            WSH.Echo i & ": " & CDbl(str) & " + 1 = " & CDbl(str) + 1
            WSH.Echo i & ": " & str & " + 1 = " & str + 1
        Else
            WSH.Echo "Is not a numeric value in " & i & ": " & str
        End If
        WSH.Echo vbCRLF & "Now computing another value for output:"
        WSH.Echo i & ": " & 3.141 & " * 10^3 + 1 = " & 3.141 * 10^3 + 1
        WSH.Echo i & ": " & 3,141 & " * 10^3 + 1 = " & 3,141 * 10^3 + 1
    Next
Next
'############################ Add1.vbs ################################

You see the different results in French? In the French locale conversion
the correct number of digits is checked, otherwise it results in an
error. In other language conversions it's not. SetLocale refers only to
the output of strings, but also to the conversion of input strings into
the correct VBScript format for a calculation of digits.

The locale conversion routine parses the digits for separation signs and
removes them all, but not in the french version, there they will be only
removed if the number of digits is right (three!). The behaviour of
VBScript seems a little bit astonishing, I have to confess. Maybe I have
understand you wrong because I have not seen your code and what do you 
want.

-- 
ЯR

[toc] | [prev] | [next] | [standalone]


#11112

From"R.Wieser" <address@not.available>
Date2015-07-11 20:17 +0200
Message-ID<55a15d43$0$2859$e4fe514c@news2.news.xs4all.nl>
In reply to#11111
Ruediger,

> Ok, it's a little bit confusing, I have expanded the code a little bit:

I'm sorry, but I still don't.

For both of the types of values some of the converted CDbl() results do not
show any "decimal point" (either a dot or a comma).  See the first group,
'en-??' and for the second group 'de' and 'nl'.

> You see the different results in French?

Yep, I did see that.  It looks like their value gets checked better than for
the others.   Oh well, the frenchies always thought of themselves as
"better" than the rest of the world. :-)

> Maybe I have understand you wrong because I have not
> seen your code and what do you want.

My origional problem is not (specific) code related.   Its the way VBScript
seems to handle implicite coercion different than explicite coercion
("3.4"+1 versus CDbl("3.4")+1).

To be honest though, I just tried to re-reproduce the effect (which I
thought I already saw earlier), and simply can't ... <huh> :-(

A *later* discovery/problem was that VBScript is quite cavalier with where
it accepts thousands-seperator symbols (like in *everywhere*).

Regards,
Rudy Wieser


-- Origional message:
Ruediger Roesler <worm.composter@nospam.arcornews.de> schreef in
berichtnieuws d0d14lFdt6gU1@mid.individual.net...
> R.Wieser <address@not.available> typed:
>
> >> And a variable of the type double is always written
> >> with a decimal point.
> >
> > I'm not at all sure if I understand you here, as the output of your
> > own code already shows otherwise ...
>
> Sorry, it did not.
>
> Ok, it's a little bit confusing, I have expanded the code a little bit:
>
> '############################ Add1.vbs ################################
> For Each str In WSH.Arguments
>     For Each i In Array("de-de", "en-us", "en-gb", "nl-nl", "fr-fr")
>         SetLocale (i)
>         WSH.Echo vbCRLF & "Calculate the value of " & str & " plus 1:"
>         If IsNumeric(str) Then
>             WSH.Echo i & ": " & CDbl(str) & " + 1 = " & CDbl(str) + 1
>             WSH.Echo i & ": " & str & " + 1 = " & str + 1
>         Else
>             WSH.Echo "Is not a numeric value in " & i & ": " & str
>         End If
>         WSH.Echo vbCRLF & "Now computing another value for output:"
>         WSH.Echo i & ": " & 3.141 & " * 10^3 + 1 = " & 3.141 * 10^3 + 1
>         WSH.Echo i & ": " & 3,141 & " * 10^3 + 1 = " & 3,141 * 10^3 + 1
>     Next
> Next
> '############################ Add1.vbs ################################
>
> You see the different results in French? In the French locale conversion
> the correct number of digits is checked, otherwise it results in an
> error. In other language conversions it's not. SetLocale refers only to
> the output of strings, but also to the conversion of input strings into
> the correct VBScript format for a calculation of digits.
>
> The locale conversion routine parses the digits for separation signs and
> removes them all, but not in the french version, there they will be only
> removed if the number of digits is right (three!). The behaviour of
> VBScript seems a little bit astonishing, I have to confess. Maybe I have
> understand you wrong because I have not seen your code and what do you
> want.
>
> --
> ?R
>

[toc] | [prev] | [next] | [standalone]


#11113

FromTodd Vargo <tlvargo@sbcglobal.netz>
Date2015-07-11 14:26 -0400
Message-ID<mnrn5d$ijp$1@news.albasani.net>
In reply to#11107
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)

[toc] | [prev] | [standalone]


Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web