|
|
 |
|
|
|
|
|
|
|
|
Visual Basic 2008 9.0 .NET Examples and Ebook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Numeric Literals without Type Coercion
| Each literal expression ( without type coercion ) formed by an integral numeric value, will be regarded ( by the compiler ) as an Integer or Long expression.
When the represented value falls out of the Integer range, it will be regarded as an Long expression ( at least if it fits in the range of Long ).
Each literal expression ( without type coercion ) formed by an numeric decimal ( with digits after the decimal separator ), will be regarded ( by the compiler ) as an Double expression ( at least if it fits in the range of Double ). |
| Module Example1
Sub Main()
Console.WriteLine("Integer :")
Console.WriteLine("Min Value : " & Integer.MinValue)
Console.WriteLine("Max Value : " & Integer.MaxValue)
Console.WriteLine("Max Literal Value : " & 2147483647)
Console.WriteLine()
Console.WriteLine("Long :")
Console.WriteLine("Min Value : " & Long.MinValue)
Console.WriteLine("Max Value : " & Long.MaxValue)
Console.WriteLine("Max Literal Value : " & 9223372036854775807)
Console.WriteLine()
Console.WriteLine("Double :")
Console.WriteLine("Negative Min ( Literal ) Value : " & _
-1.7976931348623157E+308)
Console.WriteLine("Negative Max ( Literal ) Value : " & _
-4.94065645841247E-324)
Console.WriteLine("Zero ( Literal ) : " & 0.0)
Console.WriteLine("Positive Min ( Literal ) Value : " & _
+4.94065645841247E-324)
Console.WriteLine("Positive Max ( Literal ) Value : " & _
+1.7976931348623157E+308)
Console.ReadLine()
End Sub
End Module Download Broncode |
| Output : Integer :
Min Value : -2147483648
Max Value : 2147483647
Max Literal Value : 2147483647
Long :
Min Value : -9223372036854775808
Max Value : 9223372036854775807
Max Literal Value : 9223372036854775807
Double :
Negative Min ( Literal ) Value : -1,79769313486232E+308
Negative Max ( Literal ) Value : -4,94065645841247E-324
Zero ( Literal ) : 0
Positive Min ( Literal ) Value : 4,94065645841247E-324
Positive Max ( Literal ) Value : 1,79769313486232E+308 |
| An expression -2147483648 that tries to represent the minimum Integer value will be regarded ( by the compiler ) as a Long expression. This expression is composed of the unary negation operator '-' and numeric literal '2147483648'. The parser read the numeric part '2147483648', and tries to imply the unary negation operator '-'. But the numeric part '2147483648' doesn't fit the 'Integer' range, an therefore will be regarded as a 'Long' expression.
Expression '-9223372036854775808' will ( for the same reason ) be refused by the compiler because '9223372036854775808' doesn't fit in the range of 'Long'. This expression leads to an "overflow" error. |
Up
Numeric Literals with Type Coercion
| Type coercion allows to form numeric literals of other datatypes then Integer, Long or Double.
By using a type character as suffix one could define the datatype of a numeric literal. |
| Datatype : Type character :
Byte <none>
SByte <none>
Short S
UShort US
Integer I
UInteger UI
Long L
ULong UL
Single F ( "Float" )
Double R ( "Real" )
Decimal D |
| Module Example2
Sub Main()
Dim value As Decimal = 9223372036854775808D
End Sub
End Module Download Broncode |
Up
Hexadecimal and Octal Literals
| Usually integral literals are formed using the decimal scale ( base 10 ). Using a hexadecimal ( base 16 ) or octal ( base 8 ) scale is possible, but then use prefixes &H and &O. |
| Module Example3
Sub Main()
Dim value1 As Short = &HF
Console.WriteLine(value1)
Dim value2 As Short = &H10
Console.WriteLine(value2)
Dim value3 As Short = &O7
Console.WriteLine(value3)
Dim value4 As Short = &O10
Console.WriteLine(value4)
Console.ReadLine()
End Sub
End Module Download Broncode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|