Search code examples
excelvbainternationalizationdecimalnumber-formatting

Variable using decimal comma instead of decimal point


I have been using Excel VBA for a while now and I have come across a problem that I have never encountered before. I am using someone elses computer that is set up as Polish, so the decimal separator is set to comma. But even when I had my computer set up similarly in the past I did not have any problem.

This current project creates a drawing in Visio.

So,

I have a variable of type double that is calculated as pgeWidth = 550 / 1.4

What I would expect is that VBA would calculate pageWidth = 392.857... However what VBA is doing is pgeWidth = 392,857... If I put a break in and check the value of pgeWidth it shows the value with a comma separator. pgeWidth is then set to the page width property in Visio which thinks it should be 392857.... mm wide which obviously gives an error.

Why is VBA using a comma decimal separator instead of a point?


Solution

  • If you want to pass the value further with point, consider converting variable to a string and then replacing comma with point:

    pgeWidth = replace(CStr(pgeWidth), ",",".")