(vb编程)---优化代码
If now = a1 Then a1.BorderStyle = 0: Timer1.Enabled = False
If now = a2 Then a2.BorderStyle = 0: Timer1.Enabled = False
If now = a3 Then a3.BorderStyle = 0: Timer1.Enabled = False
If now = a4 Then a4.BorderStyle = 0: Timer1.Enabled = False
If now = a5 Then a5.BorderStyle = 0: Timer1.Enabled = False
If now = a6 Then a6.BorderStyle = 0: Timer1.Enabled = False
If now = a7 Then a7.BorderStyle = 0: Timer1.Enabled = False
If now = a8 Then a8.BorderStyle = 0: Timer1.Enabled = False
If now = a9 Then a9.BorderStyle = 0: Timer1.Enabled = False
参考答案:楼上的错了
for i = 1 to 9
If now = ai Then ai.BorderStyle = 0: Timer1.Enabled = False
next
编译时它只会把ai当成变量,而不会代入i值
建议楼主把Picture控件做成组,即:
1.把A1更名为A
2.复制-粘贴,这样系统会问你是否创建数组控件,按‘是’
3.粘贴粘贴再粘贴,这样就得到A(0),A(1),A(2),...,A(9)
4.删除A(0)
然后
dim i as integer
for i = 1 to 9
If now = a(i) Then a(i).BorderStyle = 0: Timer1.Enabled = False
next