在VB中,可以使用Dim語句來定義數組,并使用賦值語句將值賦給數組的元素。
以下是一些定義和賦值數組的示例:
Dim numbers(4) As Integer
Dim names(2) As String
names(0) = "John"
names(1) = "Mary"
names(2) = "Tom"
Dim matrix(2, 2) As Integer
matrix(0, 0) = 1
matrix(0, 1) = 2
matrix(0, 2) = 3
matrix(1, 0) = 4
matrix(1, 1) = 5
matrix(1, 2) = 6
matrix(2, 0) = 7
matrix(2, 1) = 8
matrix(2, 2) = 9
Dim numbers() As Integer = {1, 2, 3, 4, 5}
Dim names() As String = {"John", "Mary", "Tom"}
這些示例展示了如何定義和賦值不同類型和維度的數組。根據需要,可以根據具體的情況選擇適合的方法。