一段VBA源代码的意思
Subaa()Range("a1:a30")=""DimnumAsLong,arr(1To30)AsLong,arr2(1To30,0)AsLong,xAsLongt1=...
Sub aa()
Range("a1:a30") = ""
Dim num As Long, arr(1 To 30) As Long, arr2(1 To 30, 0) As Long, x As Long
t1 = Timer
For x = 1 To 30
arr(x) = x
Next x
For x = 1 To 30
num = Int(Rnd() * (30 - x) + 1) '-----a语句
arr2(x, 0) = arr(num) '-----下面一句对arr数组重新排序,本句为赋值
arr(num) = arr(30 - x + 1)
Next x
Range("a1").Resize(30) = arr2
MsgBox "运行时间" & Format(Timer - t1, "0.000") & "秒"
End Sub
主要是循环那一段是什么意思。读不懂那一段是什么意思。 展开
Range("a1:a30") = ""
Dim num As Long, arr(1 To 30) As Long, arr2(1 To 30, 0) As Long, x As Long
t1 = Timer
For x = 1 To 30
arr(x) = x
Next x
For x = 1 To 30
num = Int(Rnd() * (30 - x) + 1) '-----a语句
arr2(x, 0) = arr(num) '-----下面一句对arr数组重新排序,本句为赋值
arr(num) = arr(30 - x + 1)
Next x
Range("a1").Resize(30) = arr2
MsgBox "运行时间" & Format(Timer - t1, "0.000") & "秒"
End Sub
主要是循环那一段是什么意思。读不懂那一段是什么意思。 展开
2个回答
展开全部
Sub aa()
Range("a1:a30") = ""
Dim num As Long, arr(1 To 30) As Long, arr2(1 To 30, 0) As Long, x As Long
t1 = Timer
For x = 1 To 30
arr(x) = x
Next x
For x = 1 To 30
num = Int(Rnd() * (30 - x) + 1) '在1-(31-x)之间随机取一个值如num=5
arr2(x, 0) = arr(num) '将这个随机值赋予数组arr2
arr(num) = arr(30 - x + 1) '将数组arr中的最大值赋给刚己取走的值num,用于缩小下一步num的取值范围,以达到num每次取值都不重复
Next x
Range("a1").Resize(30) = arr2
MsgBox "运行时间" & Format(Timer - t1, "0.000") & "秒"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询