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

VB.Net program to demonstrate the CUShort() function

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

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

Syntax :

CUShort(val)

Parameters :

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

Return Value :

The CUShort() function will return an unsigned short integer number that has been converted.

Program :

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


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

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 = CUShort(n1)
Console.WriteLine("Unsigned Short integer Number: {0}", num)

num = CUShort(n2)
Console.WriteLine("Unsigned Short integer Number: {0}", num)

num = CUShort(n3)
Console.WriteLine("Unsigned Short integer Number: {0}", num)

num = CUShort(n4)
Console.WriteLine("Unsigned Short integer Number: {0}", num)

We converted the value of the specified variable to an unsigned short integer in the above code and printed it on the console screen.


No Sidebar ads