原帖及讨论:http://bbs.bccn.net/thread-49756-1-1.html 学VB就到这来了,感觉这好!呵呵, 经过几天的学习,总结一下,做点东西,当是自己的作业吧!请大家帮忙完善一下! 才学,所以写的不是很规矩,也很烦杂。
内容: 做个登陆程序,以VB+Access。 功能: 1、验证。验证用户名的正确与否、密码与用户名符合与否 2、人性化设计。 ①、输入用户名后,无论是鼠标移动到密码框,还是按“Tab”键到密码框,都搜索用户名的存在与否,但不报错 ②、输入密码后,选者状态在“确定”按钮上。 ③、确定后检验,用户名为空时,光标停在用户名框,密码空停密码输入框。 控件: TextBox、CommandButton、PictureBox、Timer、ADO
程序内容: ①:控件 2 TextBox 2 CommandButton 1 PictureBox 1 Timer ②:程序 'form1程序 Private Sub Command1_Click() Unload Me End Sub Private Sub Command2_Click() Dim ConStr As String If text_user.Text = "" Then MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "登陆错误" text_user.SetFocus Exit Sub End If Set cn = New ADODB.Connection Set rs = New ADODB.Recordset ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "/ttj02.Mdb" cn.Open ConStr cn.CursorLocation = adUseServer rs.Open "Select * from dbuser", cn, adOpenKeyset, adLockPessimistic If rs.RecordCount > 0 Then If text_user.Text <> "" Then Set rs1 = New ADODB.Recordset Dim TextUserName TextUserName = Left(text_user.Text, 4) rs1.Open "Select * From dbuser Where User_nb= '" & TextUserName & "'", cn, adOpenKeyset, adLockPessimistic If rs1.RecordCount > 0 Then text_user.Text = Left(text_user.Text, 4) & rs1.Fields("user_zhuwu") Text_password.SetFocus If Text_password <> "" Then If rs1.Fields("User_Nb") = TextUserName And rs1.Fields("User_password") = Text_password.Text Then Form3.Show Unload Me Else MsgBox "密码错误!", vbExclamation + vbOKCancel, "登陆错误" text_user.Text = "" Text_password = "" text_user.SetFocus End If Else MsgBox "请输入密码!", vbExclamation + vbOKCancel, "登陆错误" End If Else MsgBox "沒有用戶信息,請確定!", vbExclamation + vbOKCancel, "登陆错误" text_user.Text = "" Text_password = "" text_user.SetFocus Exit Sub End If rs.Close End If End If End Sub Private Sub Text_password_LostFocus() If text_user.Text = "" Then text_user.SetFocus Else If Text_password.Text <> "" Then Command2.SetFocus End If End If End Sub Private Sub Text_password_Validate(Cancel As Boolean) If text_user.Text = "" Then text_user.SetFocus Else If Text_password.Text = "" Then Text_password.SetFocus Else Command2.SetFocus End If End If End Sub Private Sub text_user_LostFocus() If text_user.Text <> "" Then Dim ConStr As String Set cn = New ADODB.Connection Set rs2 = New ADODB.Recordset ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "/ttj02.Mdb" cn.Open ConStr cn.CursorLocation = adUseServer rs2.Open "Select * From dbuser Where User_nb= '" & TextUserName & "'", cn, adOpenKeyset, adLockPessimistic If rs2.RecordCount > 0 Then text_user.Text = text_user & rs2.Fields("user_zhuwu") Text_password.SetFocus rs2.Close Else text_user.Text = text_user.Text Text_password.SetFocus Exit Sub End If Else text_user.SetFocus End If End Sub Private Sub text_user_Validate(Cancel As Boolean) Dim ConStr As String Set cn = New ADODB.Connection ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "/ttj02.Mdb" cn.Open ConStr cn.CursorLocation = adUseServer Dim TextUserName TextUserName = Left(text_user.Text, 4) If text_user.Text <> "" Then Set rs3 = New ADODB.Recordset rs3.Open "Select * From dbuser Where User_nb= '" & TextUserName & "'", cn, adOpenKeyset, adLockPessimistic If rs3.RecordCount > 0 Then text_user.Text = Left(text_user.Text, 4) & rs3.Fields("user_zhuwu") Text_password.SetFocus rs3.Close Else text_user.Text = Left(text_user.Text, 4) Text_password.SetFocus Exit Sub End If End If End Sub
'form2程序 Private Sub Form_Load() Me.Show Me.Timer1.Interval = 3000 Me.Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Form1.Show Unload Me End Sub 呵呵 没看昏吧?? 大家下下去弄弄!谢谢大家的支持! 推荐新手学习用! 点击下载该附件  
|