VB.Net Tutorial/Data Type/Data Type Convert

Материал из VB Эксперт
Версия от 12:54, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

CByte: convert to byte

Module Tester
    Public Sub Main()
        Dim iInteger As Integer = 5280
        Dim lLong As Long
        Dim bytByte As Byte
        Dim sngSingle As Single
        Dim dblDouble As Double
        Dim decDecimal As Decimal
        Console.Writeline("Convert to a Byte: {0}", CByte(iInteger))
    End Sub
End Module
Unhandled Exception: System.OverflowException: Arithmetic operation resulted in an overflow.
   at Tester.Main()

CDbl: convert to double

Module Tester
    Public Sub Main()
        Dim iInteger As Integer = 5280
        Dim lLong As Long
        Dim bytByte As Byte
        Dim sngSingle As Single
        Dim dblDouble As Double
        Dim decDecimal As Decimal
        Console.WriteLine("Convert to a Double: {0}", CDbl(iInteger) / 6.123)
    End Sub
End Module
Convert to a Double: 862.322390984811

CDec: convert to decimal

Module Tester
    Public Sub Main()
        Dim iInteger As Integer = 5280
        Dim lLong As Long
        Dim bytByte As Byte
        Dim sngSingle As Single
        Dim dblDouble As Double
        Dim decDecimal As Decimal
        Console.WriteLine("Convert to a Decimal: {0}", CDec(iInteger) / 34)
    End Sub
End Module
Convert to a Decimal: 155.29411764705882352941176471

CLng: convert integer to long

Module Tester
    Public Sub Main()
        Dim iInteger As Integer = 5280
        Dim lLong As Long
        Dim bytByte As Byte
        Dim sngSingle As Single
        Dim dblDouble As Double
        Dim decDecimal As Decimal
        Console.WriteLine("Convert to a Long: {0}", CLng(iInteger) * CLng(iInteger))
    End Sub
End Module
Convert to a Long: 27878400

CSng: convert to Single

Module Tester
    Public Sub Main()
        Dim iInteger As Integer = 5280
        Dim lLong As Long
        Dim bytByte As Byte
        Dim sngSingle As Single
        Dim dblDouble As Double
        Dim decDecimal As Decimal
        Console.WriteLine("Convert to a Single: {0}", CSng(iInteger) / 3.4)
    End Sub
End Module
Convert to a Single: 1552.94117647059