1. 10新建一个窗体,然后在窗体上创建两个标签,标题分别是“口令”和“允许次数”,一个命令按钮标题是“确定”,两个文本框的名称分别为text1 和text2,其中text1用来输入口令(输入时,显示“*”),无初始内容;text2的初始内容为3。在运行时,在text1中输入口令后,单击确定,如果输入的是“123654”,则在text1中显示“口令正确”;如果输入其它内容,单击确定后,弹出如图所示的错误对话框,并且在text2中的数字减少1。最多可以输入3次口令,若3次输入都错误,则禁止再次输入。你可以帮忙解决一下吗?
'下列属性都可以直接在VB的属性列表中设定值
Label1.Caption="口令"
Label2.Caption="允许次数"
Command1.Caption="确定"
Text1.PasswordChar = "*"
Text1.Text=""
Text2.Enabled = False
Text2.Text="3"
End SubPrivate Sub Text2_Change()
If CInt(Text2.Text) = 0 Then
Text1.Enabled = False
End If
End SubPrivate Sub Command1_Click()
If CInt(Text2.Text) > 0 Then
If Text1.Text = "123654" Then
Text1.Text = "口令正确"
Else
Text2.Text = CInt(Text2.Text) - 1
End If
ElseIf CInt(Text2.Text) = 0 Then
Text1.Enabled = False
End If
End Sub'上述代码已经通过了测试,可以使用。
啥都不爲,就爲了分.Private Sub Command1_Click()
If Text1.Text = "123654" Then
Text1.PasswordChar = ""
Text1.Text = "口令正确"
Else
MsgBox "口令错误!"
Text2.Text = CStr(CInt(Text2.Text) - 1)
If Text2.Text = "0" Then Text1.Enabled = False
End If
End SubPrivate Sub Form_Load()
Label1.Caption = "口令"
Label2.Caption = "允许次数"
Text1.Text = ""
Text1.PasswordChar = "*"
Text2.Text = 3
End Sub