求VB之工程代码
来源:百度知道 编辑:UC知道 时间:2024/06/07 10:43:00
先将text1的password属性设为“?”;
代码如下:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Len(Text1.Text) <> 6 Then
MsgBox "请输入6位密码!"
Exit Sub
End If
If Text1.Text = "123456" Then
Text2.Text = "密码正确"
Else
Text2.Text = "密码错误"
Text1.Text = ""
Text1.SetFocus
End If
End If
End Sub
向窗口添加 Text1 和 Text2,具体代码如下:(其实 Text1.SetFocus 是不必要的,按下回车时焦点本身就在Text1)
Private Sub Form_Load()
With Text1
.MaxLength = 6
.PasswordChar = "?"
End With
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13
If Text1.Text = "123456" Then
Text2.Text = "正确"
Else
Text1.