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

VB.Net program to demonstrate the CBool() function

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

The function CBool() is used to convert the value of different data types to an integer type.

Syntax :

CBool(val)

Parameters :

  • val: This is an integer value given.

Return Value :

A converted Boolean value will be returned by the CBool() function.

Program :

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

'VB.Net program to demonstrate the CBool() function.


Module Module1
    Sub Main()
        Dim result As Boolean = False
        Dim n1 As Integer = 10
        Dim n2 As Integer = 0
        Dim n3 As Integer = -1       
        result = CBool(n1)
        Console.WriteLine("Boolean value: {0}", result)
        result = CBool(n2)
        Console.WriteLine("Boolean value: {0}", result)
        result = CBool(n3)
        Console.WriteLine("Boolean value: {0}", result)
    End Sub
End Module
	
Output:
Boolean value: True
Boolean value: False
Boolean value: True

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created four result variables, n1, n2, and n3, in the Main() method, which are initialized with False, 10, 0, and -10.

result = CBool(n1)
Console.WriteLine("Boolean value: {0}", result)

result = CBool(n2)
Console.WriteLine("Boolean value: {0}", result)

result = CBool(n3)
Console.WriteLine("Boolean value: {0}", result)

In the above code, the value of the specified variable is converted to a Boolean value, where the non-zero value is converted to True, and the zero value is converted to False, and then printed on the console screen.


No Sidebar ads