有一个数组,一秒种往里面添加一个数字,并且当前的数字显示在label2上面.我写的代码如下:Option ExplicitPrivate Sub Command1_Click()
Timer1(0).Enabled = True
End SubPublic Sub Form_Load()
Dim n As Integer
For n = 0 To 7
Timer1(n).Enabled = False
Timer1(n).Interval = 1000
Next
End Sub
Private Sub Timer1_Timer(Index As Integer)
If Index = 0 Then
Dim n As Integer
n = 0
n = n + 1
tp1(n) = n
Label2.Caption = Str(n)
End If
End Sub可是为什么label只出来一个数字就不变化了呢?还请各位高手指点!即时给分!!!!!!!
Timer1(0).Enabled = True
End SubPublic Sub Form_Load()
Dim n As Integer
For n = 0 To 7
Timer1(n).Enabled = False
Timer1(n).Interval = 1000
Next
End Sub
Private Sub Timer1_Timer(Index As Integer)
If Index = 0 Then
Dim n As Integer
n = 0
n = n + 1
tp1(n) = n
Label2.Caption = Str(n)
End If
End Sub可是为什么label只出来一个数字就不变化了呢?还请各位高手指点!即时给分!!!!!!!
解决方案 »
- vb中如何获取button控件的text属性?
- Server.CreateObject 的调用失败
- vb中OLE文件查询!
- vb6如何连接oracle10,在线等
- 关于一个VB类的题目的求教。。
- 新手求教:用vb如何将指定文件作为附件发送?
- 如何制作VB的安装程序?
- 怎么将数据库中的查询的值返回到某个变量中?
- API:RegEnumValue???
- EXCEL vba 点击按钮随机弹出图片 image
- 郁闷, 程序的几个窗体不小心保存在别的文件夹里了,现在要打包,提示缺少窗体,把 它们都拷回来也不行,求救sos
- 遇到错误: "[Microsoft][ODBC Microsoft Access Driver]字符串数据,右截断 (null)"
Private Sub Timer1_Timer(Index As Integer)
If Index = 0 Then
Static n As Integer
'n = 0
n = n + 1
tp1(n) = n
Label2.Caption = Str(n)
End If
End Sub
试试看
tp1(n) = n
这句话有问题 数组控件要用 for …… next
Dim n As Integer
For n = 0 To 7
Timer1(n).Enabled = False
Timer1(n).Interval = 1000
Next
End Sub
这些语句好象没用的,timer1要click触发,index就是0
首先,在timer控件数组中实际能用的控件只有index=0的。
在每次触发时,n因为是局部变量,每次都被初始化为0,然后加1,所有你
tp1()数组的元素没有增加,而且在设置lable的caption时也犯了同样的错误。
应定义为private n as integer(在Option Explicit区)
static n(1 to 8) as integer通过一个定时器就可以了
dim a as integer,array(8)as integer
private sub Timer1_Timer()
array(a)=cstr(a)
a=a+1
Label1.Caption=cstr(array(a))
End Sub