如题所述
Dim a As Integer
Private Sub Command1_Click()
If Text1 <> "123" Then
If a < 2 Then
a = a + 1
Text1 = ""
MsgBox "密码错误,请重新输入,你还有" & 3 - a & "次机会"
ElseIf a = 2 Then
MsgBox "对不起,因3次输入错误,所以无权使用"
Unload Me
End If
ElseIf Text1 = "123" Then
MsgBox "欢迎使用!"
a = 0 '可用可不用
End If
End Sub
Private Sub Command1_Click()
If Text1 <> "123" Then
If a < 2 Then
a = a + 1
Text1 = ""
MsgBox "密码错误,请重新输入,你还有" & 3 - a & "次机会"
ElseIf a = 2 Then
MsgBox "对不起,因3次输入错误,所以无权使用"
Unload Me
End If
ElseIf Text1 = "123" Then
MsgBox "欢迎使用!"
a = 0 '可用可不用
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答 2011-03-23
Dim intC as integer,Pass as string
Private Sub Form_Load()
Pass="123456"'设置密码
dim InputPass as string
intC=3'输入次数
while intC
if intC=3 then inputPass=inputbox("请您输入密码!") else inputPass=inputbox("您输入的密码有误,您还有" & intC & "次机会输入密码,请你正确输入密码!")
if Pass=inputPass then
intC=0'退出循环
msgbox "登陆成功!"
else
intC=intC-1
if intC=0 then End'最后一次输入错误退出程序
end if
wend
End Sub
Private Sub Form_Load()
Pass="123456"'设置密码
dim InputPass as string
intC=3'输入次数
while intC
if intC=3 then inputPass=inputbox("请您输入密码!") else inputPass=inputbox("您输入的密码有误,您还有" & intC & "次机会输入密码,请你正确输入密码!")
if Pass=inputPass then
intC=0'退出循环
msgbox "登陆成功!"
else
intC=intC-1
if intC=0 then End'最后一次输入错误退出程序
end if
wend
End Sub
第2个回答 2011-03-23
先设定变量x等于输入错误次数,如果大于3则结束程序
Dim x As Integer
Private Sub Command1_Click()
If Text1.Text <> "111" Then
Text1.Text = ""
x = x + 1
Label1.Caption = x
If x > 3 Then
End
End If
End If
End Sub
Dim x As Integer
Private Sub Command1_Click()
If Text1.Text <> "111" Then
Text1.Text = ""
x = x + 1
Label1.Caption = x
If x > 3 Then
End
End If
End If
End Sub
第3个回答 2018-03-22
elseif