Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the CBool() function
By Nidhi Last Updated : November 11, 2024
CBool() function in VB.Net
The CBool() function is used to convert different data types value into the integer type.
Syntax
CBool(val)
Parameter(s)
- val: It is a given integer value.
Return Value
The CBool() function will return a converted boolean value.
VB.Net code to demonstrate the example of CBool() function
The source code to demonstrate the CBool() function is given below. The given program is compiled and executed successfully.
'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
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created four variables result, n1, n2, and n3 that 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, we converted the value of the specified variable into boolean value, here non-zero value is converted into True and zero converted into False and then we printed them on the console screen.
VB.Net Basic Programs »