> 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