Dutch Math

E

Ed

I need to write program code for 'international' applications.

I have set my Region settings to Dutch(Netherlands).

In Dutch (and other major languages), commas represent the decimal point and
periods represent the thousands separators.

I wrote this simple formula:

Dim mynumber As Single
Dim mynumber2 As Single
Dim mynumber3 As Single
Dim mynumber4 As Single
mynumber = 1,50
mynumber2= 5
mynumber3=mynumber + mynumber2
mynumber4=mynumber3 + 1.5

I get a 'Compile Error, Expected End of Statment' message with the row
"mynumber = 1,5" highlighted.
What am I doing wrong? How can I overcome this?

Unfortunately, it seems not to be simple matter of putting a period in place
of the comma, for when I actually try to run a calculation using decimals
as, the results come out in commas. Chaining calculations becomes more than
very confusing (at least to me), because of the fact that the answer
returned after the first calculation is expressed in Dutch (e.g., 1,5), but
the next entry must be entered in 'American'. And if the initial values are
picked up as string variables from an input box, it becomes even more
confusing.

Are there resources to help explain this?
 
P

Peter Jamieson

I don't know of a comprehensive source in the issues of internationalization
and localization, but
a. it's a large and difficult area to deal with.
b. you could start here:

http://en.wikipedia.org/wiki/Internationalization
I get a 'Compile Error, Expected End of Statment' message with the row
"mynumber = 1,5" highlighted.
What am I doing wrong? How can I overcome this?

In essence, when you write code in VBA (or VB, or whatever you are using)
you have to follow the syntax rules of that language, not the language set
up in Control Panel on Windows.

So

Dim mynumber As Double
mynumber = 1,5

does not work because in VBA you have to use "." as the decimal point in
numeric literals

However,


Dim mynumber As Double
mynumber = 1.5
msgbox mynumber

should display 1.5 on a system with typical US locale settings and 1,5 with
typical Dutch locale settings. That is because you are then calling a method
that takes account of the Windows locale settings.

i.e.
the /language/ always uses the "."
the methods have been written to take account of the locale. (Although you
may well be able to find examples where they don't, and you are free not to
do so in your own methods).

Another example is

Dim mynumber As Double
mynumber = "1.5"
msgbox mynumber

This will show 1.5 in the US locale and 15 in the Dutch locale. Why? Because
VBA tries to coerce the string "1.5" to the target data type (Double) and
uses a conversion function to do it (it may even call cdbl() - I don't
know). The conversion function is locale-sensitive: in the US locale, it
sees the "." as a decimal point and converts the number to 1.5. In the Dutch
locale it sees the "." as a "thousands separator" (even if it is in the
wrong place) and ignores it. Actually I don't know how it works /exactly/
but it will be something like that.

When it comes to data input (e.g. via a dialog box) the thing to remember is
that data typed on a keyboard always starts out as a sequence of keystrokes,
which are then turned into a sequence of characters. A piece of software
that allows you to define a "numeric" input field will probably try to
validate that that seqeunce of characters looks like a number before
accepting it or converting it. When you use such a piece of software you are
in effect dependent on what input it is willing to see as a valid number and
how it converts the sequence of characters into a number.

Things can get very tricky when trying to internationalise/localise. For
example, when you have numeric fields in Word documents, the numeric
formatting switch has to be in the current locale - e.g. on a Dutch system
you would need

{ REF mynumber \#".0,00" } to format a number such as 1000 as 1.000,00

arguably, the picture switch syntax should be locale-invariant like the VBA
numeric literal syntax. but it isn't. Worse, if the locale uses a space as
the thousands separator (e.g. most if not all French locales) then using the
equivalent

{ REF mynumber \#" 0,00" } to output 1000 as 1 000,00

just doesn't work. And so on...

Hope that gives you a start anyway...I'm sure others here have far more
experience of the details of how VBA behaves in this area than I do.

Peter Jamieson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top