Val() 函數用於將數字字符串轉換為整數。
用法:
Val(str)
參數:
- str:它是一個指定的數字字符串。
返回值:
Val() 函數將返回一個整數值。
程序/源代碼:
下麵給出了演示 Val() 函數的源代碼。給定的程序已成功編譯並執行。
'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
輸出:
Integer value:111 Integer value:222 Integer value:333 Press any key to continue . . .
說明:
在上麵的程序中,我們創建了一個包含 Main() 方法的模塊 Module1。在 Main() 方法中,我們創建了四個變量 result,n1、n2 和 n3,它們初始化為 0、"111"、"222" 和 "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)
在上麵的代碼中,我們將數字字符串轉換為整數值,然後將它們打印在控製台屏幕上。
相關用法
- VB.NET LTrim()用法及代碼示例
- VB.NET DateTime FromBinary()用法及代碼示例
- VB.NET CLng()用法及代碼示例
- VB.NET RTrim()用法及代碼示例
- VB.NET GetChar()用法及代碼示例
- VB.NET Array Reverse()用法及代碼示例
- VB.NET DateTime ToBinary()用法及代碼示例
- VB.NET Array Resize()用法及代碼示例
- VB.NET CInt()用法及代碼示例
- VB.NET CULng()用法及代碼示例
- VB.NET CDbl()用法及代碼示例
- VB.NET LCase()用法及代碼示例
- VB.NET Array ConstrainedCopy()用法及代碼示例
- VB.NET Array Clear()用法及代碼示例
- VB.NET Array LastIndexOf()用法及代碼示例
- VB.NET String Join()用法及代碼示例
- VB.NET String IsNullorWhitSpace()用法及代碼示例
- VB.NET InStr()用法及代碼示例
- VB.NET Array BinarySearch()用法及代碼示例
- VB.NET CByte()用法及代碼示例
注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the Val() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。