?? module1.bas
字號:
Attribute VB_Name = "ModuleMain"
Option Explicit
Public UserType As Boolean '如果是true那么是超級用戶
Public cn As ADODB.Connection '公共連接對象
Public searchSQL As String
Public IsAdmin As Boolean '判斷是否為系統管理員登陸
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'創建一個連接
Public Function MakeConnection() As String
Set cn = New ADODB.Connection
On Error GoTo connecterr
With cn
.CursorLocation = adUseClient
'.ConnectionString = " provide=sqloledb:datasourse=學籍.mdb:DefaultDir=" & CheckPath(App.path) & ";ID=;PWD=;PASSWORD=197967yh"
.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=db5.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;" '數據庫密碼 ,防止被人用其它軟件打開數據庫
.Open
End With
MakeConnection = "OK"
Exit Function
connecterr:
Dim i As Integer
Dim sError As String
If cn.Errors.Count > 0 Then
For i = 0 To cn.Errors.Count - 1
sError = sError & cn.Errors(i).Number & ":" & cn.Errors(i).Description & vbCrLf
Next i
End If
MakeConnection = sError
Exit Function
End Function
Public Function AnalyseStdNum(Ustdnum As String, Lstdnum As String) As Integer
'98076030 “98”是指哪一屆;“07”是指市校的代號;
'“6”是指分校的代號; “0”是指班級號;“30”是指學號
If Len(Ustdnum) <> 8 Or Len(Lstdnum) <> 8 Then
AnalyseStdNum = -1
Else
If Ustdnum = Lstdnum Then '單一學號的查找
AnalyseStdNum = 8
Exit Function
ElseIf Left$(Ustdnum, 6) = Left$(Lstdnum, 6) Then '班級單位查找
AnalyseStdNum = 6
Exit Function
ElseIf Left$(Ustdnum, 5) = Left$(Lstdnum, 5) Then '分校單位查找
AnalyseStdNum = 5
Exit Function
ElseIf Left$(Ustdnum, 4) = Left$(Lstdnum, 4) Then '市校單位查找
AnalyseStdNum = 4
Exit Function
ElseIf Left$(Ustdnum, 2) = Left$(Lstdnum, 2) Then '同屆學生查找
AnalyseStdNum = 2
Exit Function
Else
AnalyseStdNum = 0
End If
End If
End Function
Public Sub MakeCenter(frm As Form) '使窗口顯示在屏幕中央
Dim intx2 As Integer, inty2 As Integer
intx2 = (Screen.Width - frm.Width) / 2
inty2 = (Screen.Height - frm.Height) / 2
frm.Left = intx2
frm.Top = inty2
End Sub
Public Function CheckPath(path As String) As String '檢測數據庫路徑是否以"\"結束
If Right$(path, 1) = "\" Then
CheckPath = path
Else
CheckPath = path & "\"
End If
End Function
'程序入口
Sub Main()
searchSQL = "SELECT * FROM 學生"
UserType = False
IsAdmin = False
Load DlgLogin '載入登陸對話框
DlgLogin.Show
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -