Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the Val() function
By Nidhi Last Updated : November 14, 2024
Val() function in VB.Net
The Val() function is used to convert the numeric string into an integer number.
Syntax
Val(str)
Parameter(s)
- str: It is a specified numeric string.
Return Value
The Val() function will return an integer value.
VB.Net code to demonstrate the example of Val() function
The source code to demonstrate the Val() function is given below. The given program is compiled and executed successfully.
'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
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 four variables result, n1, n2, and n3 that are initialized with 0, "111", "222", and "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)
In the above code, we converted the numeric string into an integer value, and then we printed them on the console screen.
VB.Net Basic Programs »