vb数组定义
一、一维数组只有一个下标,数学上形如数列{ai}表示的数据均可用一维数组来处理。注意数组的输入与输出方法。Private Sub Command1_Click() Dim a(100) As Integer Dim s As Integer For i = 1 To 100 a(i) = i Next i End
一、一维数组
只有一个下标,数学上形如数列{ai}表示的数据均可用一维数组来处理。注意数组的输入与输出方法。
Private Sub Command1_Click()
Dim a(100) As Integer
Dim s As Integer
For i = 1 To 100
a(i) = i
Next i
End Sub
说明:⑴为了养成编程的一些好的习惯,我们建议大家无论是否需要,还是带上s= 0,这样也便于理解。
--------------------------------------------------------------------------
二、二维数组
通常是指由两个下标的数组元素所组成的数组。一个二维表格就是一个二维数组。
数学上形如矩阵{aij}表示的数据均可用二维数组来处理。
仍需注意数组的输入与输出方法。
Private Sub Command1_Click()
Dim a(1 To 4, 1 To 5) As Integer
Dim b(1 To 4, 1 To 5) As Integer
Dim c(1 To 4, 1 To 5) As Integer
For i = 1 To 4
For j = 1 To 5
a(i, j) = Int(Rnd * 90) + 10
Next j
Next i
End Sub
Dim a(1 To 4, 1 To 5) As Integer
Dim b(1 To 4, 1 To 5) As Integer
Dim c(1 To 4, 1 To 5) As Integer
For i = 1 To 4
For j = 1 To 5
a(i, j) = Int(Rnd * 90) + 10
Next j
Next i
End Sub
-----------------------------------------------------------------------
三、字符串数组的定义 Dim a(1 To 10) As String
-----------------------------------------------------------------
四、多维数组
由两个以上下标的数组元素所组成的数组。几何上一个立体坐标就可以用三维数组来表示
Private Sub Command1_Click()
Dim a(1 To 3, 1 To 4, 1 To 3) As Integer
For i = 1 To 3
For j = 1 To 4
For k = 1 To 3
a(i, j, k) = Int(Rnd * 90) + 10
Next k
Next j
Next i
For j = 1 To 4
For k = 1 To 3
a(i, j, k) = Int(Rnd * 90) + 10
Next k
Next j
Next i
end Sub
更多推荐
所有评论(0)