简单的vb问题~~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/10 09:56:15
代码如下:
Private Sub Command1_Click()
Static ClickStr As Integer
ClickStr = ClickStr + 1
Label1.Caption = "单击了" & ClickStr & "下!"
End Sub
-------------------------------------------
Private Sub Timer1_Timer()
If ClickStr > 10 Then
MsgBox "成功"
Else
MsgBox "失败"
End If
End Sub
————————————————
timer的Interval的值为3000
================================
为什么ClickStr 大于10,时间到的时候却显示“失败”?

你认为Static是定义静态变量和数组变量
但是,在你的程序中他是一个局部变量,他的作用范围在Private Sub Command1_Click() 过程内.而在过程Private Sub Timer1_Timer() 里是不可见的.在这里你用到,只是相当于一个新的变量.这就是vb他的变量不需要定义也可以使用的缺点吧.

错误知道了---自己动手,丰衣足食!