vb程序设计编写程序验证输入密码是否正确
2017-05-24
展开全部
在窗体form1上添加一个textbox和commandbutton控件,如果textbox的值是123则显示另外一个窗体( ow)如果错误则用msgbox显示密码错误.设置Textbox的PasswordChar为*.
Option Explicit
Const vbKeyDecPt = 46
Private Sub Command1_Click()
If Val(Text1) = 123 Then
Form2.Show
Me.Hide
Else
MsgBox "密码不正确,请重新输入", vbExclamation + vbOKOnly, "提示"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Exit Sub
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) '限制textbox只能输入数字
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
Exit Sub
ElseIf KeyAscii = vbKeyReturn Then
Call Command1_Click
Else
KeyAscii = 0
End If
End Sub
Option Explicit
Const vbKeyDecPt = 46
Private Sub Command1_Click()
If Val(Text1) = 123 Then
Form2.Show
Me.Hide
Else
MsgBox "密码不正确,请重新输入", vbExclamation + vbOKOnly, "提示"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Exit Sub
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) '限制textbox只能输入数字
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
Exit Sub
ElseIf KeyAscii = vbKeyReturn Then
Call Command1_Click
Else
KeyAscii = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
人民的名义
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询