?? module1.bas
字號:
Attribute VB_Name = "Module1"
Private strsql As String
Private strconn As String
Private rs As New ADODB.Recordset
Private msg1 As String
Public tt1 As Integer '是否可以更改密碼的標記
Sub reg()
On Error Resume Next
If Form1.Text1.Text = "" Then
MsgBox "用戶名不能為空"
Exit Sub '如果用戶名為空即退出
End If
If Form1.Text2.Text = "" Then
MsgBox "密碼不能為空"
Exit Sub '如果密碼為空即退出
End If
strconn = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\reg.mdb"
strsql = "select * from xulang"
With rs 'rs獲取reg.mdb的記錄集,rs(0)為一記錄的第一字段(name),rs(1)為一記錄的第二字段(password)
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn
.Source = strsql
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open '用ADO接口打開access數據庫reg.mdb
End With
rs.MoveFirst '移到reg.mdb數據庫的第一條記錄
Do While Not rs.EOF '從第一條記錄開始查找滿足條件的記錄
If rs(0) = Form1.Text1.Text Then '首先叛斷是否有此人
If Form1.Option1.Value = True Then
If rs(1) = Form1.Text2.Text Then '有此人,且密碼政正確則登錄成功
MsgBox "登錄成功"
Unload Form1
Exit Sub
End If
End If
If Form1.Option1.Value = True Then
If rs(1) <> Form1.Text2.Text Then
MsgBox "密碼不正確"
Form1.Text2.Text = ""
Exit Sub
End If
End If
If Form1.Option2.Value = True Then '有此人,則不能注冊
MsgBox "此用戶名已有人注冊,請再試著用別的網名注冊"
Form1.Text2.Text = ""
Form1.Text1.Text = ""
Exit Sub
End If
If Form1.Option3.Value = True Then '有此人,可以改寫密碼
If rs(1) = Form1.Text2.Text Then '如果密碼正確
If tt1 = 1 Then '如果tt1=1則用窗體2的數據改寫舊密碼
rs(1) = Form2.Text1.Text
tt1 = 0
MsgBox "密碼修改成功"
Unload Form2
Form1.Text1.Text = ""
Form1.Text2.Text = ""
Exit Sub
Else '顯示窗體2輸入新密碼
Form2.Show
Exit Sub
End If
End If
If rs(1) <> Form1.Text2.Text Then '舊密碼不正確
MsgBox "密碼不正確"
Form1.Text2.Text = ""
Exit Sub
End If
End If
End If
rs.MoveNext
Loop
If rs.EOF Then '如果沒有此人,則rs.eof必為真,這樣可以進行"注冊"
If Form1.Option1.Value = True Then '沒有此人,不能登錄
MsgBox "此用戶名還沒有注冊,請注冊再使用"
Form1.Text2.Text = ""
Exit Sub
End If
If Form1.Option2.Value = True Then
If rs(0) <> Form1.Text1.Text Then '沒有此人,可以"注冊"
msg1 = MsgBox("你要注冊用戶名 " & Form1.Text1.Text & " 密碼 " & Form1.Text2.Text & " 嗎?", vbYesNo, "注冊提示")
If msg1 = vbYes Then
rs.AddNew '插入注冊信息
rs(0) = Form1.Text1.Text
rs(1) = Form1.Text1.Text
rs.Update
MsgBox "注冊成功"
Unload Form1
Exit Sub
Else
Form1.Text1.Text = ""
Form1.Text2.Text = ""
Exit Sub
End If
End If
End If
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -