在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"}
这些示例展示了如何定义和赋值不同类型和维度的数组。根据需要,可以根据具体的情况选择适合的方法。