This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Why Do I Get a Type Mismatch Error When Running My VBScript on a Non-US Computer

Updated May 9, 2023

Reported In

Software

  • DIAdem Base
  • DIAdem Full
  • DIAdem Professional

Issue Details

I wrote a VBScript that uses the CDbl() method to cast a variant to a double precision floating point number. The numbers I am casting use a comma "," as the thousands separator and a period "." as the decimals separator. Running the application on my computer works fine, but when a customer runs it on a non-US localized version of Windows they receive an error alerting him that a "Type Mismatch Error" has occurred. Why is this error occurring?

Solution

If your VB Script is running on a computer that is localized for a country that uses different decimal or thousands separators than the ones present in your variable, the CDbl() method will return an error. This Type Mismatch error occurs because the function will not understand the format of the number that is being cast. To fix this error, you will have to guarantee that the number that is being cast is in the local format, or use another function.

Additional Information

The Visual Basic CDbl() method uses the current operating system regional settings to determine the decimal and thousands separator of the variable it is casting. In the United States, the period "." is used as a decimal separator. On the other hand, in most European countries, the comma "," is used as the decimal separator. Furthermore, in the United States, a comma is used as the thousands separator to isolate groups of three digits to the left of the decimal separator. In several European countries, a period or a space is used for this purpose.