Microsoft KB Archive/820657

= You receive an &quot;Overflow&quot; error if you use -9223372036854775808 (Long.MinValue) in Visual Basic .NET or in Visual Basic 2005 =

Article ID: 820657

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



SYMPTOMS
If you use -9223372036854775808 for the minimum value of the Long data type in your Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 application, you cannot build your application, and you receive the following error message:

Overflow.



CAUSE
This problem occurs because Microsoft Visual Basic .NET, Microsoft Visual Basic 2005, Microsoft Visual C# 2005, and Microsoft Visual C# .NET have syntactic grammar that does not include the leading hyphen (-) as part of the numeric literal. The parser reads the numeric part, and then the parser applies the unary minus (-) operator to the number. Your Visual Basic .NET application parses the minimum value of the Long data type as 9223372036854775808. This number is greater than maximum value for the Long data type. Therefore, you receive the error message mentioned in the &quot;Symptoms&quot; section of this article.

Note The problem only occurs in Visual Basic .NET or in Visual Basic 2005, because Visual C# .NET or Visual C# 2005 has a rule for the numeric type hyphen prefix.



WORKAROUND
To work around the problem, use one of the following procedures:   Use the MinValue property of the data type, as in the following example: Dim lValue as Long = Int64.MinValue -or-   Use the numeric expression that evaluates to the minimum value for the Long data type. For example, instead of using -9223372036854775808, use -9223372036854775807 -1, as in the following code: Dim lValue as Long = -9223372036854775807 -1 



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Create a console application by using Visual Basic .NET or Visual Basic 2005.  Copy the following code to the Sub Main method: Dim lValue As Long = -9223372036854775808  On the Build menu, click Build Solution.

You receive the error mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">