FIX: CSng Converted to CDbl for String Literals and Variables

Last reviewed: October 30, 1997
Article ID: Q127031
3.00 WINDOWS kbenv kbbuglist

The information in this article applies to:

  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

Code using the function CSng() within Visual Basic is automatically converted to a CDbl by the compiler.

CAUSE

If a string literal, such as 1.1, or a string variable is placed inside of the CSng function, Visual Basic converts the function to CDbl. The following code demonstrates the problem: Dim S As Single S=CSng("1.1")

When you run a program containing this code, Visual Basic changes it to this code:

   Dim S As Single S=CDbl("1.1")

WORKAROUND

To work around the problem, use another function that operates on the string. Then place this result inside the CSng function. For example, use this:

   S=CSng(Val("100"))

STATUS

This bug was corrected in Microsoft Visual Basic version 4.0 for Windows.


Additional reference words: 3.00 buglist3.00 fixlist4.00
KBCategory: kbenv kbbuglist
KBSubcategory: EnvtDes
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.