VB控件数组问题
有两个picture控件数组,我想第二个数组picture2的任一控件的图片是picture1的任一控件的图片,但第二个数组的图片不能重复。如果像下面一样的话,pictu...
有两个picture控件数组,我想第二个数组picture2的任一控件的图片是picture1的任一控件的图片,但第二个数组的图片不能重复。
如果像下面一样的话,picture2中的空件中有可能出现了相同的图片,要怎么实现每张图片都不相同呢?
Private Sub Form_Load()
Randomize
For i = 0 To 6
Picture1(i) = LoadPicture(App.Path + "\pic\" & i & ".jpg")
Next
For j = 0 To 6
Picture2(j) = LoadPicture(App.Path + "\pic\" & Int(Rnd * 7) & ".jpg")
Next
End Sub 展开
如果像下面一样的话,picture2中的空件中有可能出现了相同的图片,要怎么实现每张图片都不相同呢?
Private Sub Form_Load()
Randomize
For i = 0 To 6
Picture1(i) = LoadPicture(App.Path + "\pic\" & i & ".jpg")
Next
For j = 0 To 6
Picture2(j) = LoadPicture(App.Path + "\pic\" & Int(Rnd * 7) & ".jpg")
Next
End Sub 展开
展开全部
这个是产生随机数的,很高效的代码
Option Explicit
Option Base 1
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Const Nums = 10000
Private Sub Command1_Click()
Dim t As Long
Dim Num(Nums) As Long
Dim i, n As Long
Dim s As String
t = timeGetTime
Randomize
For i = 1 To Nums
n = Int(Rnd * Nums) + 1
If Num(n) = 0 Then
Num(n) = n
s = s & n & ","
Else
i = i - 1
End If
Next i
Text1.Text = s
t = timeGetTime - t
MsgBox t
End Sub
Option Explicit
Option Base 1
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Const Nums = 10000
Private Sub Command1_Click()
Dim t As Long
Dim Num(Nums) As Long
Dim i, n As Long
Dim s As String
t = timeGetTime
Randomize
For i = 1 To Nums
n = Int(Rnd * Nums) + 1
If Num(n) = 0 Then
Num(n) = n
s = s & n & ","
Else
i = i - 1
End If
Next i
Text1.Text = s
t = timeGetTime - t
MsgBox t
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询