帮忙修改VB代码。我创建了一个image控件数组,5张一样的图片,起先全为不可见,每2秒钟出现其中一个。
代码如下PrivateSubTimer1_Timer()DimaAsString,bAsInteger,cAsInteger,nAsIntegern=Indexa="01...
代码如下
Private Sub Timer1_Timer()
Dim a As String, b As Integer, c As Integer, n As Integer
n = Index
a = "01234"
b = Len(a) - 1
Randomize
c = Rnd() * b
If n = c Then
Image2(n).Visible = True
End If
Print c ‘现在只有c=0时才显示的出图片
End Sub 展开
Private Sub Timer1_Timer()
Dim a As String, b As Integer, c As Integer, n As Integer
n = Index
a = "01234"
b = Len(a) - 1
Randomize
c = Rnd() * b
If n = c Then
Image2(n).Visible = True
End If
Print c ‘现在只有c=0时才显示的出图片
End Sub 展开
3个回答
展开全部
程序已经经过实测无误,控件定义和你的源程序一样,直接全部拷贝过去就可用。图片是随机在5张图片中出现,2秒一次,满意请及时采纳,谢谢
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 2000
End Sub
Private Sub Timer1_Timer()
Dim k As Integer
Randomize Timer
For k = 0 To 4
Image2(k).Visible = False
Next k
k = Int(Rnd * 5)
Image2(k).Visible = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 2000
End Sub
Private Sub Timer1_Timer()
Dim k As Integer
Randomize Timer
For k = 0 To 4
Image2(k).Visible = False
Next k
k = Int(Rnd * 5)
Image2(k).Visible = True
End Sub
追问
那我原来的代码错在哪儿呢?
追答
Private Sub Timer1_Timer()
Dim a As String, b As Integer, c As Integer, n As Integer
n = Index 'Index没初始化,所以Index=0,结果n=0
a = "01234"
b = Len(a) - 1 '这行也有问题,得到的b=4,所以随机数应该在0~3之间
Randomize '那么第五个image图片永远也显示不出来
c = Rnd() * b 'c 是随机数,而n=0
If n = c Then '所以这行比较的结果只能是c=0时才为真
Image2(n).Visible = True '也就是你看到的只有c=0时才有显示
End If
Print c ‘现在只有c=0时才显示的出图片
End Sub
展开全部
Dim P As Integer, K As Integer, I As Integer
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
For I = 0 To 4
Image1(I).Visible = False
Next I
End Sub
Private Sub Timer1_Timer()
For I = 0 To 4
Image1(I).Visible = False
Next I
P = P + 1
If P = 1 Then
Image1(K).Visible = True
K = K + 1
If K > 4 Then K = 0
Else
P = 0
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
For I = 0 To 4
Image1(I).Visible = False
Next I
End Sub
Private Sub Timer1_Timer()
For I = 0 To 4
Image1(I).Visible = False
Next I
P = P + 1
If P = 1 Then
Image1(K).Visible = True
K = K + 1
If K > 4 Then K = 0
Else
P = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
c = Rnd() * b ==》 c = int(Rnd() * b)要取整,不然得到的是小数,整数的概率非常低所以很难刚好等于整数。
更多追问追答
追问
改了以后也还是只有0的时候才出现图片..
追答
完整代码。N 是什么?index又是什么?单步调试你会不会?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询