这是人登录,注册在一起的窗体,登录,注册分别是两个单选按钮OPTION1,OPTION2, 确定是COMMAND1,其中后台的代码是这样的 Dim strinput As String Dim code As String Dim reco As String, strtemp As String Dim i As Integer, length As Integer Dim intasc As Integer
Private Sub Command1_Click() If Text1.Text = "" Then MsgBox "用户名不能为空", 48, "警告": Exit Sub End If
If Text2.Text = "" Then MsgBox "密码不能为空", 48, "警告": Exit Sub End If If Option2.Value = True Then If Text2.Text <> Text3.Text Then MsgBox "两次口令不同,请重新输入", 48, "警告": Exit Sub End If
strinput = Text2.Text i = 1 code = "" length = Len(strinput) Do While i <= length strtemp = Mid(strinput, i, 1) If (strtemp >= "A" And strtemp <= "Z") Or (strtemp >= "a" And strtemp <= "z") Then intasc = Asc(strtemp) + 4 code = Left(code, i - 1) & Chr(intasc) Else code = Left(code, i - 1) & strtemp End If i = i + 1 Loop Open "e:\login.dat" For Append As #1 //这是什么意思,什么是.dat文件,我看了看是自动生成的,我想把注册后的信息写到我的ACCESS表中。我不会用.DAT的文件。 Write #1, Text1, code Close #1 Label4.Caption = "恭喜你,注册成功" Else Open "e:\login.dat" For Input As #1 Do Until EOF(1) Input #1, UserName, Password UserName = Trim(UserName) Password = Trim(Password) If Text1.Text = UserName Then i = 1 code = "" length = Len(Password) Do While i <= length strtemp = Mid(Password, i, 1) If (strtemp >= "A" And strtemp <= "^") Or (strtemp >= "a" And strtemp <= "~") Then intasc = Asc(strtemp) - 4 code = Left(code, i - 1) & Chr(intasc) Else code = Left(code, i - 1) & strtemp End If i = i + 1 Loop Exit Do End If Loop Close #1 If Trim(Text2.Text) = Trim(code) Then Label4.Caption = "登录成功" Timer1.Enabled = True
3.MsgBox "两次口令不同,请重新输入", 48, "警告": Exit Sub 你这是修改密码时用的方法,而不是登录时用的. 你可以 在通用区宣告 Dim ErrCount& 在你的Command1_Click事件中用户名或密码错误则 ErrCount = ErrCount +1 if ErrCount>=3 then unload me '错误三次退出系统
Open "e:\login.dat" For Input As #1 Line Input #1, aa s=split(aa,",") '这里假设你的.dat文件内容UserName与Password是以逗号分隔的 UserName = Trim(s(0)) Password = Trim(s(1)) '********************* close #1