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

VB.Net program to demonstrate the CSByte() function

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

The function CSByte() is used to convert the value of various data types into a signed byte type.

Syntax :

CSByte(val)

Parameters :

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

Return Value :

A converted signed byte number is returned by the CSByte() function.

Program :

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


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

Explanation:

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

num = CSByte(n1)
Console.WriteLine("Signed Byte Number: {0}", num)

num = CSByte(n2)
Console.WriteLine("Signed Byte Number: {0}", num)

num = CSByte(n3)
Console.WriteLine("Signed Byte Number: {0}", num)

num = CSByte(n4)
Console.WriteLine("Signed Byte Number: {0}", num

We converted the value of the specified variable to a signed byte in the code above and printed it on the console screen.


No Sidebar ads