Re: Decimal commas instead of decimal points
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 8 Aug 2008 17:50:50 +0100
Don't mix the locale-aware functions (CStr, CDbl, etc) with the
non-locale-aware functions (e.g. Val, Str) on the same data. Use the
appropriate one depending on whether you want the localised decimal
separator (e.g. if the end-user will see it) or a fixed "." separator (e.g.
if the data is private to the application and may need to be portable across
locales).
If you mix them then you'll run into the difficulties you mentioned.
Also, if you're reading data values with Input # then make sure it was
originally written with Write # (not Print #). Like Val/Str, these
statements always use "." as the decimal separator, and always use "," as
the field separator. As long as you use the correct pair of statements
together than everything should work fine
Tony Proctor
"A. Bulsari" <invalid.user@xxxxxx> wrote in message
news:g7hjad$t47@xxxxxxxxxxxxxx
In article <g7f6j5$20n$1@xxxxxxxxxxxxxxxxxxxxxx>,
Tony Proctor <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
When you format a decimal number (e.g. with CStr or Format$), VB
automatically uses the correct decimal-point character for your locale
The trouble with this is that it will write commas into files, and
then when I try to read the file, it won't be able to. Or is there a
simple way to make Visual Basic also read 2,5 from a text file as two
and a half? A bad alternative would be to write the file in binary
format, but that makes it impossible for humans to read and modify.
Similarly, when you try to decode a textual representation of a number
(e.g.
with CSng or CDbl) then it automatically expect the correct decimal-point
character
Hence, there should be no hard work involved
I am now wondering if I should change the code in hundreds (dozens?)
of places from Val(Text**) to CSng(Text**). This should work in
English as well as European locales.
Note that the VB language (i.e. what you program with) always uses "." and
never uses ",". This is sometimes called the "programming locale". Make
sure
you don't confuse the language definition with what a VB application does
Incidentally, the Str function always formats a decimal number with ".",
and
the Val function always expects ".". These alternatives to CStr and CDbl
are
the only two VB functions that don't honour the current locale. I prefer
to
view these as "honouring the programming locale" and they can be useful
when
manipulating data files independently of the locale.
Sorry I did not understand this completely. Can I read a text file with
numbers
(and few strings) earlier written by Visual Basic with commas using CStr
and
CSng/CDbl on text picked up by Input #1, length, width, fraction assuming
I would
have to Dim length as string instead of single?
Tony Proctor
Thanks for your input.
With kind regards,
A. Bulsari
<invalid.user@xxxxxx> wrote in message news:g7e557$pc@xxxxxxxxxxxxxx
Many people in Europe use decimal commas instead of decimal points.
How do you deal with this problem? I suspect Visual Basic 6.0 might
know it should read numbers with commas, but it does not seem to be
trivial.
This problem occurs in text boxes as well as in reading and writing
text files.
With kind regards,
A. Bulsari
.
- References:
- Decimal commas instead of decimal points
- From: invalid . user
- Re: Decimal commas instead of decimal points
- From: Tony Proctor
- Re: Decimal commas instead of decimal points
- From: A. Bulsari
- Decimal commas instead of decimal points
- Prev by Date: Re: Decimal commas instead of decimal points
- Next by Date: Re: Decimal commas instead of decimal points
- Previous by thread: Re: Decimal commas instead of decimal points
- Next by thread: Re: Decimal commas instead of decimal points
- Index(es):
Relevant Pages
|