在VB中,可以使用以下方法進行數據類型轉換:
Dim str As String = "123"
Dim num As Integer = CType(str, Integer)
Dim obj As Object = "Hello"
Dim str As String = DirectCast(obj, String)
Dim num1 As Double = 3.14
Dim num2 As Integer = CInt(num1)
Dim str As String = "123"
Dim num As Integer = Integer.Parse(str)
需要注意的是,在進行數據類型轉換時,要確保轉換是安全的,避免出現數據類型不匹配或溢出的情況。