VB的一个用户登录实例

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:13:11
你好!这是我用VB写的一个“用户登录”实例,为什么在运行的时候总是说变量未定义,然后txtpassword就被显示成黄色,能告诉我原因吗?代码如下“
Option Explicit
Public intmytimes As Integer
Const maxtimes As Integer = 3

Private Sub Form_Load()
intmytimes = 1
cbousername.AddItem "管理员"
cbousername.AddItem "操作员1"
cbousername.AddItem "操作员2"
End Sub
Private Sub cmdok_Click()
If cbousername.Text <> "" Then
If txtpassword.Text = "" Then
MsgBox "请输入密码", , "提示信息"
txtpassword.SetFocus
Exit Sub
End Sub
If txtpassword.Text <> "11" Then
If intmytimes > maxtimes Then
MsgBox "您无权使用该软件!", , "提示窗口"
End
Else
intmytimes = intmytimes + 1
MsgBox "密码不正确,请重新输入!", , "提示窗口"
txtpassword.SetFocus
Else
MsgBox "登录成功!", , "提示窗口"
End If
Else
MsgBox "操作员不能为空!", , "提示窗口&q

添加一个TEXTBOX控件,即文本框控件,(name)属性设置为txtpassword,passwordChar属性设置为*

属性在右侧设置

Private Sub cmdok_Click()
If cbousername.Text <> "" Then
If txtpassword.Text = "" Then
MsgBox "请输入密码", , "提示信息"
txtpassword.SetFocus
Exit Sub
End Sub
这一段最后一行的End Sub 错了,应该改为End If。

txtpassword指的是你必须新建一个名为txtpassword的文本框控件用于输入密码

Option Explicit
Public intmytimes As Integer
Const maxtimes As Integer = 3

Private Sub Form_Load()
intmytimes = 1
cbousername.AddItem "管理员"
cbousername.AddItem "操作员1"
cbousername.AddItem "操作员2"
End Sub
Private Sub cmdok_Click()
If cbousername.Text <> "" Then
If txtpassword.Text = "" Then
MsgBox "请输入密码", , "提示信息"
txtpassword.SetFocus
Exit Sub
End If
If txtpassword.Text <> "11" Then