Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the CLng() function

VB.Net program to demonstrate the CLng() function

Write a VB.Net program to demonstrate the CLng() function

The function CLng() is used to convert the value of different data types into a long integer type.

Syntax :

CLng(val)

Parameters :

  • val: It may be a variable with different types of data.

Return Value :

A converted long integer number is returned by the CLng() function.

Program :

Below is the source code for demonstrating the CLng() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim num As Long = 0
        Dim n1 As Single = 10.25
        Dim n2 As Integer = 12
        Dim n3 As Double = 25.35
        Dim n4 As String = "122"
        num = CLng(n1)
        Console.WriteLine("Long Integer Number: {0}", num)
        num = CLng(n2)
        Console.WriteLine("Long Integer Number: {0}", num)
        num = CLng(n3)
        Console.WriteLine("Long Integer Number: {0}", num)
        num = CLng(n4)
        Console.WriteLine("Long Integer Number: {0}", num)
    End Sub
End Module
	
Output:
Long Integer Number: 10
Long Integer Number: 12
Long Integer Number: 25
Long Integer Number: 122

Explanation:

We created a Module1 module in the above program, which contains the Main() method. Five variables num, n1, n2, n3, and n4 have been created in the Main() method and are initialize with 0, 10.25, 12, 25.35, and 122.

num = CLng(n1)
Console.WriteLine("Long Integer Number: {0}", num)

num = CLng(n2)
Console.WriteLine("Long Integer Number: {0}", num)

num = CLng(n3)
Console.WriteLine("Long Integer Number: {0}", num)

num = CLng(n4)
Console.WriteLine("Long Integer Number: {0}", num)

We converted the value of the specified variable to a long integer number in the code above and printed it on the console screen.


No Sidebar ads