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

VB.Net program to demonstrate the Val() function

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

To convert a numeric string into an integer number, the Val() function is used.

Syntax :

Val(str)

Parameters :

  • str: This is a numeric string specified.

Return Value :

An integer value will be returned by the Val() function.

Program :

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

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


Module Module1
    Sub Main()
        Dim result As Integer = 0
        Dim n1 As String = "111"
        Dim n2 As String = "222"
        Dim n3 As String = "333"
        result = Val(n1)
        Console.WriteLine("Integer value: {0}", result)
        result = Val(n2)
        Console.WriteLine("Integer value: {0}", result)
        result = Val(n3)
        Console.WriteLine("Integer value: {0}", result)
    End Sub
End Module
	
Output:
Integer value: 111
Integer value: 222
Integer value: 333

Explanation:

We created a Module1 module in the program above that contains the Main() method. Four variables result, n1, n2, and n3 that are initialized with 0, "111", "222" and "333" are created in the Main() method.

result = Val(n1)
Console.WriteLine("Integer value: {0}", result)

result = Val(n2)
Console.WriteLine("Integer value: {0}", result)

result = Val(n3)
Console.WriteLine("Integer value: {0}", result)

We converted the numeric string to an integer value in the above code, and then we printed it on the console screen.


No Sidebar ads