For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > Problem with locale









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with locale
Ivan

2005-02-05, 3:59 am

Hi,

I have the following problem:
I read a numeric (double) value stored in simple text file (i.e "2.25") and
convert it to a double using CDbl. Works fine until used on a client with
non-english locale. For example, if German locale is set, which uses (,) as a
decimal separator and (.) as a group separator, then the CDbl returns
(correctly, I guess) 225. Is there any straightforward way to deal with this
(besides changing locales back and forth, or detecting locales and
manipulating the string?)

Thanks,
Ivan

Max Kudrenko

2005-02-07, 4:08 pm

Ivan,

If you use your app in Germany, you should have German locale and CDbl
will always recognize it. Type Conversion Functions are internationally
aware and work properly for any one locale. So your problem isn't quite
clear as both the app and the user will treat all the formating the
same way which is the expected behaviour.

Max Kudrenko
Brainbench MVP Program for Visual Basic
www.brainbench.com


Ivan wrote:
> Hi,
> I have the following problem:
> I read a numeric (double) value stored in simple text file (i.e

"2.25") and
> convert it to a double using CDbl. Works fine until used on a client

with
> non-english locale. For example, if German locale is set, which uses

(,) as a
> decimal separator and (.) as a group separator, then the CDbl returns


> (correctly, I guess) 225. Is there any straightforward way to deal

with this
> (besides changing locales back and forth, or detecting locales and
> manipulating the string?)
> Thanks,
> Ivan


Ivan

2005-02-07, 4:08 pm

Max,

Thanks for your comment. The problem that I have is that the installer
instals on the German user the same config. file that has a textual value :
something like this: value = 2.25. The application parses this file, reads
the string value "2.25" (note that it will be always with a period, no matter
what locale it was installed on), and then depending on the locale, CDbl will
return 225 on a German computer and 2.25 on an English one.

Hope this clarifies my problem

Ivan

"Max Kudrenko" wrote:

> Ivan,
>
> If you use your app in Germany, you should have German locale and CDbl
> will always recognize it. Type Conversion Functions are internationally
> aware and work properly for any one locale. So your problem isn't quite
> clear as both the app and the user will treat all the formating the
> same way which is the expected behaviour.
>
> Max Kudrenko
> Brainbench MVP Program for Visual Basic
> www.brainbench.com
>
>
> Ivan wrote:
> "2.25") and
> with
> (,) as a
>
> with this
>
>

Max Kudrenko

2005-02-07, 9:03 pm

Ivan,

Yews, I understand your problem and it is exactly that - your problem,
not the application or setup shortcoming. If you recall, many
applications have different versions for different countries (read
locales) so if the program is complicated enough you may need to follow
their lead. If the app is simple, it is possible to have many localized
versions in one program. In this case you need to take care of such
issues as yours yourself and don't let VB righteously generate a
problem. If you know that in your setup you'll always have decimal
numbers with dot (like your "2.25") and they must be uniformly
recognized this way regardless of the current locale, create a custom
parsing routine. Or better still, for converting decimals you can
easily use Val instead of CDbl and you'll always be bound to the dot
decimal representation.

Hope this helps,

Max Kudrenko
Brainbench MVP Program for Visual Basic
www.brainbench.com


Ivan wrote:
> Max,
> Thanks for your comment. The problem that I have is that the

installer
> instals on the German user the same config. file that has a textual

value :
> something like this: value = 2.25. The application parses this file,

reads
> the string value "2.25" (note that it will be always with a period,

no matter
> what locale it was installed on), and then depending on the locale,

CDbl will[color=darkred]
> return 225 on a German computer and 2.25 on an English one.
> Hope this clarifies my problem
> Ivan
>
> "Max Kudrenko" wrote:
>
CDbl[color=darkred]
internationally[color=darkred]
quite[color=darkred]
client[color=darkred]
uses[color=darkred]
returns[color=darkred]
deal[color=darkred]
and[color=darkred]

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com