?? modmain.bas
字號:
Attribute VB_Name = "modMain"
Option Explicit
Public OFFCAT As IAgentCtlCharacter
Public OFFCATRequest As IAgentCtlRequest
Public fMainForm As frmMain
Public FirstUse As Boolean
Public OperatorNum As Integer, OperatorNameNum As Integer, _
OperatorName1 As String, OperatorName2 As String
Dim strName() As String, strType() As Long, strSize() As Long
Dim fso As New FileSystemObject
Public Const RegionNumber = 12
Sub Main()
frmSplash.Show vbModal '顯示啟動屏幕
frmSplash.Refresh
IniPathX
'是否第一次使用
Dim strAppName As String
strAppName = App.Path + "\權限表.mdb"
Dim fso As New FileSystemObject
If Not fso.FileExists(strAppName) Then
FirstUse = True
End If
If Not FirstUse Then
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.LoginSucceeded Then
'登錄失敗,退出應用程序
End
End If
Unload fLogin
End If
Set fMainForm = New frmMain '顯示主窗體
Load fMainForm
fMainForm.Show
End Sub
Public Sub IniPathX()
' Change the IniPath property to point to a different
' section of the Windows Registry for settings
' information.
Debug.Print "Original IniPath setting = " & _
IIf(DBEngine.IniPath = "", "[Empty]", _
DBEngine.IniPath)
DBEngine.IniPath = _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\" & _
"Jet\4.0\ISAM Formats\Jet 2.x"
Debug.Print "New IniPath setting = " & _
IIf(DBEngine.IniPath = "", "[Empty]", _
DBEngine.IniPath)
End Sub
Public Sub SystemInitialize()
'建立權限表
ReDim strName(5), strType(5), strSize(5)
strName(1) = "編號": strType(1) = dbInteger: strSize(1) = 2
strName(2) = "人員代號": strType(2) = dbInteger: strSize(2) = 2
strName(3) = "人員名": strType(3) = dbText: strSize(3) = 20
strName(4) = "姓名": strType(4) = dbText: strSize(4) = 20
strName(5) = "密碼": strType(5) = dbText: strSize(5) = 20
Dim strAppName As String, strTableName As String, intMax As Integer, idxName As String
strAppName = App.Path + "\權限表.mdb"
strTableName = "權限表"
intMax = 5
idxName = "編號"
DeleteFile strAppName
CreatDB strAppName, strTableName, intMax, idxName
'向權限表中添加一個記錄
Dim db As Database, rs As Recordset
Set db = Workspaces(0).OpenDatabase(strAppName, False, False)
Set rs = db.OpenRecordset(strTableName)
rs.AddNew
rs.Fields("編號") = 1
rs.Fields("人員代號") = 1
rs.Fields("人員名") = "系統管理員"
rs.Fields("姓名") = "李斌杰"
rs.Fields("密碼") = 12345
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
'建立用戶檔案
ReDim strName(23), strType(23), strSize(23)
strName(1) = "編號": strType(1) = dbLong: strSize(1) = 4
strName(2) = "戶名": strType(2) = dbText: strSize(2) = 50
strName(3) = "地址": strType(3) = dbText: strSize(3) = 50
strName(4) = "電話": strType(4) = dbText: strSize(4) = 20
strName(5) = "戶型": strType(5) = dbText: strSize(5) = 20
strName(6) = "用水性質": strType(6) = dbText: strSize(6) = 20
strName(7) = "用戶開戶": strType(7) = dbText: strSize(7) = 50
strName(8) = "開戶行": strType(8) = dbText: strSize(8) = 50
strName(9) = "帳號": strType(9) = dbLong: strSize(9) = 4
strName(10) = "納稅號": strType(10) = dbLong: strSize(10) = 4
strName(11) = "用水人數": strType(11) = dbLong: strSize(11) = 4
strName(12) = "水表直徑": strType(12) = dbLong: strSize(12) = 4
strName(13) = "水表號": strType(13) = dbLong: strSize(13) = 4
strName(14) = "始用日期": strType(14) = dbDate: strSize(14) = 8
strName(15) = "加封日期": strType(15) = dbDate: strSize(15) = 8
strName(16) = "表井位置": strType(16) = dbText: strSize(16) = 20
strName(17) = "水表裝法": strType(17) = dbText: strSize(17) = 30
strName(18) = "旁通管徑": strType(18) = dbLong: strSize(18) = 4
strName(19) = "上月讀數": strType(19) = dbLong: strSize(19) = 4
strName(20) = "終止讀數": strType(20) = dbLong: strSize(20) = 4
strName(21) = "備注": strType(21) = dbMemo: strSize(21) = 0
strName(22) = "注銷": strType(22) = dbBoolean: strSize(22) = 1
strName(23) = "分區": strType(23) = dbInteger: strSize(23) = 2
strAppName = App.Path + "\用戶檔案.mdb"
strTableName = "用戶檔案"
intMax = 23
idxName = "編號"
DeleteFile strAppName
CreatDB strAppName, strTableName, intMax, idxName
'建立水費標準庫
ReDim strName(4), strType(4), strSize(4)
strName(1) = "編號": strType(1) = dbInteger: strSize(1) = 2
strName(2) = "用戶類型": strType(2) = dbText: strSize(2) = 10
strName(3) = "收費標準": strType(3) = dbCurrency: strSize(3) = 8
strName(4) = "污水處理費": strType(4) = dbCurrency: strSize(4) = 8
strAppName = App.Path + "\水費標準庫.mdb"
strTableName = "水費標準"
intMax = 4
idxName = "編號"
DeleteFile strAppName
CreatDB strAppName, strTableName, intMax, idxName
End Sub
Public Sub CreatDB(strAppName As String, strTableName As String, intMax As Integer, idxName As String)
'創建數據庫
Dim db As Database, tb As TableDef, fld As Field, idx As Index
Set db = Workspaces(0).CreateDatabase(strAppName, dbLangGeneral, dbVersion30)
Set tb = db.CreateTableDef(strTableName)
Dim i As Integer
For i = 1 To intMax
Set fld = tb.CreateField()
With fld
.Name = strName(i)
.Type = strType(i)
.Size = strSize(i)
'這個僅用于 text
If .Type = dbText Then .AllowZeroLength = -1
End With
tb.Fields.Append fld
tb.Fields.Refresh
Next
Set idx = tb.CreateIndex(idxName)
idx.Primary = True
Set fld = idx.CreateField(idxName)
idx.Fields.Append fld
tb.Indexes.Append idx
db.TableDefs.Append tb
db.TableDefs.Refresh
db.Close
Set idx = Nothing
Set fld = Nothing
Set tb = Nothing
Set db = Nothing
End Sub
Public Sub DeleteFile(strAppName As String)
'如果已存在文件,刪除它
If fso.FileExists(strAppName) Then
Kill strAppName
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -