給你一個簡單的示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Option Explicit
Private Function GetRndInt() As Integer()
" 返回一個 Integer型別的陣列
Dim i As Long, aTemp() As Integer
Randomize
ReDim aTemp(15)
For i = 0 To 15
aTemp(i) = Rnd() * 500
Next
GetRndInt = aTemp
End Function
Private Sub Command1_Click()
Dim aTemp() As Integer
Dim i As Long
Me.Cls
aTemp = GetRndInt
Print "隨機產生的資料為:"
For i = 0 To UBound(aTemp)
Print i + 1, aTemp(i)
End Sub
執行效果:
給你一個簡單的示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Option Explicit
Private Function GetRndInt() As Integer()
" 返回一個 Integer型別的陣列
Dim i As Long, aTemp() As Integer
Randomize
ReDim aTemp(15)
For i = 0 To 15
aTemp(i) = Rnd() * 500
Next
GetRndInt = aTemp
End Function
Private Sub Command1_Click()
Dim aTemp() As Integer
Dim i As Long
Me.Cls
aTemp = GetRndInt
Print "隨機產生的資料為:"
For i = 0 To UBound(aTemp)
Print i + 1, aTemp(i)
Next
End Sub
執行效果: