VB中 怎么统计输入次数

来源:百度知道 编辑:UC知道 时间:2024/06/02 06:42:24
在一个文本框中输入密码。如果输入错误超过三次就退出。

建一个Command1,Text1.默认密码为123.
代码如下。
=============
Dim i As Integer

Private Sub Command1_Click()
If Text1.Text = "123" Then MsgBox "密码正确!": i = 0 Else MsgBox "密码错误!": i = i + 1
If i = 3 Then MsgBox "3次密码错误!": End
End Sub

Private Sub Form_Load()
Command1.Caption = "确定密码"
Text1.Text = ""
End Sub

在确定按钮中定义静态变量如
sub command1_click()
static x as integer
x= x+1
if x =3 then
command1.enable=false
end if
end sub
或者定义模块级变量如
dim x as integer
-------------------------------
sub command1_click()
x= x+1
if x =3 then
command1.enable=false
end if
end sub

用变量保存次数
dim i as long rem 全局变量,局部不行

i=i+1
if i >=3 then
end