VB.Net program to demonstrate the CSByte() function

Here, we are going to demonstrate the CSByte() function in VB.Net.
Submitted by Nidhi, on December 04, 2020 [Last updated : March 05, 2023]

CSByte() function in VB.Net

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

Syntax

CSByte(val)

Parameter(s)

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

Return Value

The CSByte() function will return a converted signed byte number.

VB.Net code to demonstrate the example of CSByte() function

The source code to demonstrate the CSByte() function is given below. The given program is compiled and executed successfully.

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

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
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 five variables num, n1, n2, n3, and n4 that 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)

In the above code, we converted the value of the specified variable into a signed byte and printed them on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.