?? module1.bas
字號:
Attribute VB_Name = "Module1"
Sub Main()
On Error GoTo Error
''系統檢測是否有date.mdb文件,如果沒有,則是系統第一次啟動,則建立之
If Dir("c:\windows\system\yy.bak") = "" Then
''注意在開始,您要確定您的工程引用了Microsoft dao 2.5/3.5 compatibility library 在"工程"==>"引用"中.
Dim WS As Workspace
Dim DB As Database
Dim TD As TableDef
Dim fldd As Field
Dim IDX As Index
Dim rd As Recordset
Set WS = DBEngine.Workspaces(0)
Set DB = WS.CreateDatabase("c:\windows\system\yy.bak", dbLangGeneral)
DB.Connect = ";pwd=andy"
Set TD = DB.CreateTableDef("date")
TD.Attributes = 0
TD.Connect = ""
TD.SourceTableName = ""
TD.ValidationRule = ""
TD.ValidationText = ""
'' Field first_time
Set fldd = TD.CreateField("first_time", 8, 8)
fldd.Attributes = 1
fldd.DefaultValue = ""
fldd.OrdinalPosition = 0
fldd.Required = False
fldd.ValidationRule = ""
fldd.ValidationText = ""
TD.Fields.Append fldd
'' Field last_time
Set fldd = TD.CreateField("last_time", 8, 8)
fldd.Attributes = 1
fldd.DefaultValue = ""
fldd.OrdinalPosition = 1
fldd.Required = False
fldd.ValidationRule = ""
fldd.ValidationText = ""
TD.Fields.Append fldd
'' Field times
Set fldd = TD.CreateField("times", 3, 2)
fldd.Attributes = 1
fldd.DefaultValue = ""
fldd.OrdinalPosition = 2
fldd.Required = False
fldd.ValidationRule = ""
fldd.ValidationText = ""
TD.Fields.Append fldd
DB.TableDefs.Append TD
DB.Close
Set DB = WS.OpenDatabase("c:\windows\system\yy.bak")
Set rd = DB.OpenRecordset("date")
With rd
.AddNew
.Fields("first_time") = Date
.Fields("last_time") = Date
.Fields("times") = 1
.Update
End With
DB.Close
'MsgBox "這是您第一次啟動本系統!您的試用期為30天,今天是第一天.謝謝使用!", 48, "安徽皖方軟件科技有限公司"
''效果如圖1 (見附件1)
enter.Show ''啟動您的主窗體
Else ''系統有date.mdb文件,則不是第一次運行,就不用建立數據庫文件了.
Dim WS2 As Workspace
Dim DB2 As Database
Dim rd2 As Recordset
Set WS2 = Workspaces(0)
Set DB2 = WS2.OpenDatabase("c:\windows\system\yy.bak", pwd = "springlover")
Set rd2 = DB2.OpenRecordset("date")
''開始檢測用戶是否修改了系統日期
rd2.MoveFirst
If rd2.Fields("last_time") > Date Then
MsgBox "對不起,您在本軟件的試用期內不可以修改系統日期,否則將取消您對本系統的試用權.如果您想繼續使用本軟件,請您恢復系統日期.謝謝合作!", 48, "安徽皖方軟件科技有限公司"
End
End If
''開始檢測是否超期
If Date - rd2.Fields("first_time") >= 60 Then ''設定試用期為30天
MsgBox "您已經啟動本系統" & rd2.Fields("times") & "次了,而且已經到了60天的試用期,如果您想繼續使用本軟件,請您到本公司注冊并購買正版的軟件! Tel:0551-2884899 QQ:11624317", 48, "安徽皖方軟件科技有限公司"
End
Else
''仍在試用期內
num% = rd2.Fields("times")
rd2.Edit
rd2.Fields("last_time") = Date
rd2.Fields("times") = num + 1
rd2.Update
'MsgBox "這是您第" & rd2.Fields("times") & "次使用本系統,您還有" & 30 - (Date - rd2.Fields("first_time")) & "天的試用期,祝您今天工作愉快!", 48, "安徽皖方軟件科技有限公司"
''效果如圖2 (見附件2)
enter.Show ''啟動您的主窗體
End If
End If
Exit Sub
Error:
MsgBox "系統錯誤!"
End Sub
Function GetIni(strPrimary, strSubKey, strIniFilePath)
Dim myFso
Dim MyFile
Dim intCount, strState
Set myFso = CreateObject("Scripting.FileSystemObject")
Set MyFile = myFso.OpenTextFile(strIniFilePath, 1, False, False)
With MyFile
Do Until .AtEndOfStream
If intCount = 0 Then
If .ReadLine = "[" & strPrimary & "]" Then
intCount = 1
End If
Else
strState = .ReadLine
If UCase(Left(strState, Len(strSubKey & "="))) = UCase(strSubKey & "=") Then
GetIni = Right(strState, Len(strState) - Len(strSubKey & "="))
End If
End If
Loop
.Close
End With
Set MyFile = Nothing
Set myFso = Nothing
End Function
Function cipher(stext As String) '加密程序
Const min_asc = 32
Const max_asc = 126
Const num_asc = max_asc - min_asc + 1
Dim offset As Long
Dim strlen As Integer
Dim i As Integer
Dim ch As Integer
offset = 123
Rnd (-1)
Randomize (offset)
strlen = Len(stext)
For i = 1 To strlen
ch = Asc(Mid(stext, i, 1))
If ch >= min_asc And ch <= max_asc Then
ch = ch - min_asc
offset = Int((num_asc + 1) * Rnd())
ch = ((ch + offset) Mod num_asc)
ch = ch + min_asc
ptext = ptext & Chr(ch)
End If
Next i
cipher = ptext
End Function
Function decipher(stext As String) '解密程序
Const min_asc = 32
Const max_asc = 126
Const num_asc = max_asc - min_asc + 1
Dim offset As Long
Dim strlen As Integer
Dim i As Integer
Dim ch As Integer
offset = 123
Rnd (-1)
Randomize (offset)
strlen = Len(stext)
For i = 1 To strlen
ch = Asc(Mid(stext, i, 1))
If ch >= min_asc And ch <= max_asc Then
ch = ch - min_asc
offset = Int((num_asc + 1) * Rnd())
ch = ((ch - offset) Mod num_asc)
If ch < 0 Then
ch = ch + num_asc
End If
ch = ch + min_asc
ptext = ptext & Chr(ch)
End If
Next i
decipher = ptext
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -