早教吧 育儿知识 作业答案 考试题库 百科 知识分享

比如1,3,7,12,13,15,19,20,23,24这10个数字中任选6个组合,VBA函数怎么写?

题目详情
比如1,3,7,12,13,15,19,20,23,24这10个数字中任选6个组合,VBA函数怎么写?
▼优质解答
答案和解析
思路:将10个数字存入数组D(1 TO 10)
产生6个范围在1--10之间但是不重复的随机数字n1,n2,n3,n4,n5,n6
取出D(N1),D(N2),D(N3),D(N4),D(N5),D(N6),就是了:
Private Sub Command1_Click()
Dim d(1 To 10) As Integer
Dim n(1 To 6) As Integer
Dim T As Integer
Dim i As Integer
Dim TF As Boolean
Dim x As Integer
d(1) = 1
d(2) = 3
d(3) = 7
d(4) = 12
d(5) = 13
d(6) = 15
d(7) = 19
d(8) = 20
d(9) = 23
d(10) = 24
'
'显示获取的6个数字
For i = 1 To 6
Print n(i),d(n(i))
Next i
End Sub