Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
2 ratings:
 5 out of 5     Rate this Document

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

Primary Software: DIAdem
Primary Software Version: 10
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I wrote a VB Script that uses the CDbl function to guarantee that a variant is cast into 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. When I run this application in my computer it works fine, but when a customer runs it on a non-US localized version of Windows here receives and error alerting him that a "Type Mismatch Error" has occurred. What is going wrong?

Solution: The Visual Basic CDbl function 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.

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 function will return an error. This Type Mismatch error will occur because the function will not understand the format of the number that is being cast. In order 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.

Related Links: Knowledge Base [2KN9IMFN]: VBScript in DIAdem

Attachments:





Report Date: 03/30/2006
Last Updated: 03/31/2006
Document ID: 3VTGC7O8

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit