Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the CShort() function
The function CShort() is used to convert the value of various data types into a short integer type.
Syntax :
CShort(val)
Parameters :
Return Value :
The CShort() function returns a short integer number converted.
Program :
The source code to demonstrate the function CShort() is given below. The program given is compiled and successfully executed.
Module Module1
Sub Main()
Dim num As Short = 0
Dim n1 As Double = 10.25
Dim n2 As Single = 12.25
Dim n3 As Integer = 25
Dim n4 As String = "122"
num = CShort(n1)
Console.WriteLine("Short integer Number: {0}", num)
num = CShort(n2)
Console.WriteLine("Short integer Number: {0}", num)
num = CShort(n3)
Console.WriteLine("Short integer Number: {0}", num)
num = CShort(n4)
Console.WriteLine("Short integer Number: {0}", num)
End Sub
End Module
Explanation:
We created a Module1 module in the program above that contains the Main() method. Five variables num, n1, n2, n3, and n4 were created in the Main() method, initialized with 0, 10.25, 12.25, 25, and 122.
num = CShort(n1) Console.WriteLine("Short integer Number: {0}", num) num = CShort(n2) Console.WriteLine("Short integer Number: {0}", num) num = CShort(n3) Console.WriteLine("Short integer Number: {0}", num) num = CShort(n4) Console.WriteLine("Short integer Number: {0}", num)
We converted the value of the specified variable to a short integer in the above code and printed it on the console screen.