469,167 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

formats real numbers

Hi!

I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?

Best regards,
Andreas Lundgren
Jul 17 '05 #1
4 5543
> I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


That could be tricky. For example, if you are using a grid-type control,
you may or may not be able to play with the display format depending on
the "robustness" of the grid control. However, if you are using simple
input and output controls, you could do something along these lines. Say
you are taking in input in a TextBox and a UseEnglish flag variable is
set to true. Then you might do something like this after the user
signals to continue...

If UseEnglish Then
NumericVariable = CDbl(Replace(Text1.Text, ".", ","))
End If

You could use CSng depending on the precision you need to work with. As
for Print'ing the result somewhere, you could possibly do this...

If UseEnglish Then
OutputText = Format$(NumericVariable, "<<anyway you want>>")
OutputText = Replace(OutputText, ",", ".")
End If
Print OutputText

Of course, your challenge will be to catch every place input and output
is taking place so that you can splice in this conversion. The key is to
convert from or to the English format immediately after input or
immediately before output. The above assumes no "thousands separators"
will be used. If they will be permitted, then something like this will
be required

If UseEnglish Then
NumericVariable = Replace(Text1.Text, ",", Chr$(1))
NumericVariable = Replace(NumericVariable, ".", ",")
NumericVariable = Replace(NumericVariable, Chr$(1), ".")
End If

with a similar treatment for output.

Rick - MVP

Jul 17 '05 #2
On 20 Jul 2004 06:45:18 -0700, d9****@efd.lth.se (Andreas) wrote:
Hi!

I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


Personally I would say don't use any 'locale aware' stuff

But if you are leaching off 3rd party dubious controls you have a
problem.
Jul 17 '05 #3
Thanks,

I feared that would be the only solution. As I work with the number
before printing them, I have to add some code when I print them.
Sometimes the printout is for example a division of two integers, so
there is a lots of hidden places where I must remember to edit...

Thanks anyway!

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<Vd********************@comcast.com>...
I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


That could be tricky. For example, if you are using a grid-type control,
you may or may not be able to play with the display format depending on
the "robustness" of the grid control. However, if you are using simple
input and output controls, you could do something along these lines. Say
you are taking in input in a TextBox and a UseEnglish flag variable is
set to true. Then you might do something like this after the user
signals to continue...

If UseEnglish Then
NumericVariable = CDbl(Replace(Text1.Text, ".", ","))
End If

You could use CSng depending on the precision you need to work with. As
for Print'ing the result somewhere, you could possibly do this...

If UseEnglish Then
OutputText = Format$(NumericVariable, "<<anyway you want>>")
OutputText = Replace(OutputText, ",", ".")
End If
Print OutputText

Of course, your challenge will be to catch every place input and output
is taking place so that you can splice in this conversion. The key is to
convert from or to the English format immediately after input or
immediately before output. The above assumes no "thousands separators"
will be used. If they will be permitted, then something like this will
be required

If UseEnglish Then
NumericVariable = Replace(Text1.Text, ",", Chr$(1))
NumericVariable = Replace(NumericVariable, ".", ",")
NumericVariable = Replace(NumericVariable, Chr$(1), ".")
End If

with a similar treatment for output.

Rick - MVP

Jul 17 '05 #4
> I feared that would be the only solution. As I work with the number
before printing them, I have to add some code when I print them.
Sometimes the printout is for example a division of two integers, so
there is a lots of hidden places where I must remember to edit...


Maybe you could construct a Sub to do the printing and in the Sub do the
Replace operation. If you take the argument ByVal, then you won't have
to worry about preserving the regional setting for the numbers inside
main section of your program. All you would have to do is switch all of
the Print statements you have to the Sub you write. VB's Find/Replace
editing in the IDE should be able to find all of the occurrences of
Print for you.

Rick - MVP

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Aaron W. West | last post: by
1 post views Thread by Roger | last post: by
4 posts views Thread by Vig | last post: by
4 posts views Thread by Zeng | last post: by
10 posts views Thread by Pavils Jurjans | last post: by
20 posts views Thread by tomerfiliba | last post: by
8 posts views Thread by aarklon | last post: by
2 posts views Thread by Koliber (js) | last post: by
16 posts views Thread by DirtyHarry | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.