?? mdldiary.bas
字號:
Attribute VB_Name = "mdlDiary"
Option Base 1
Public Type RecDiary '定義記錄
fldDate As String * 12
fldMemo As String * 1000
End Type
Public gsSql As String * 10
Public gsPath As String
Public giRecordCount As Integer '記錄總數
Public giCurrentRecord As Integer '當前記錄
Public goDiary As RecDiary '定義自定定類
Public goDiarys() As RecDiary '定義數組
Public gbFirst As Boolean
'------- ^^目的:訪問注冊表,驗證密碼.^^-----------------
Public Sub InitalizeData() '初始化數據
On Error Resume Next
Dim iFreefile%, I%
iFreefile = FreeFile()
Open gsPath & "DATA.DAT" For Random As #iFreefile Len = Len(goDiary)
giRecordCount = LOF(iFreefile) / Len(goDiary)
ReDim goDiarys(giRecordCount)
For I = 1 To giRecordCount
Get #iFreefile, I, goDiarys(I)
Next
Close #iFreefile
End Sub
Public Sub ReadData(curRecord As Integer) '讀取數據
On Error Resume Next
Dim strcaption$
riji.txtDate = goDiarys(curRecord).fldDate
riji.txtMemo = goDiarys(curRecord).fldMemo
strcaption = "每日一記 [" & Date & "] " & Time & " " & WeekdayName(Weekday(Date)) & " 記錄:" & giCurrentRecord & "/" & giRecordCount
riji.Caption = strcaption
End Sub
Public Function FindData(sql As String) As Boolean '查詢數據
On Error Resume Next
Dim I%
For I = 1 To giRecordCount
If goDiarys(I).fldDate = sql Then
giCurrentRecord = I
FindData = True
Exit For
End If
Next
ReadData giCurrentRecord
End Function
Public Function WriteData() As Boolean '新增數據
On Error Resume Next
Dim iFreefile%, I%
iFreefile = FreeFile()
Open gsPath & "DATA.DAT" For Random As #iFreefile Len = Len(goDiary)
ReDim Preserve goDiarys(giRecordCount)
goDiarys(giRecordCount).fldDate = frminput.txtDate
goDiarys(giRecordCount).fldMemo = frminput.txtMemo
goDiary = goDiarys(giRecordCount)
Put #iFreefile, giRecordCount, goDiary
giCurrentRecord = giRecordCount
ReadData (giCurrentRecord)
Close #iFreefile
WriteData = True
End Function
Public Function ModifyData() As Boolean '修改數據
On Error Resume Next
Dim iFreefile%, I%
iFreefile = FreeFile()
Open gsPath & "DATA.DAT" For Random As #iFreefile Len = Len(goDiary)
goDiarys(giCurrentRecord).fldDate = frminput.txtDate
goDiarys(giCurrentRecord).fldMemo = frminput.txtMemo
goDiary = goDiarys(giCurrentRecord)
Put #iFreefile, giCurrentRecord, goDiary
ReadData (giCurrentRecord)
Close #iFreefile
ModifyData = True
End Function
Public Sub DeleteData() '刪除數據
On Error Resume Next
Dim iFreefile%, I%, J%
I = 1: J = 1
iFreefile = FreeFile()
Open gsPath & "temp.dat" For Random As #iFreefile Len = Len(goDiary)
goDiarys(giCurrentRecord).fldMemo = "IWantToKillIt*" & goDiarys(giCurrentRecord).fldMemo '加刪除標記
For I = 1 To giRecordCount '無刪除標記的記錄,保存到臨時文件,TEMP.DAT
If Left(goDiarys(I).fldMemo, 14) <> "IWantToKillIt*" Then
goDiary = goDiarys(I)
Put #iFreefile, J, goDiary '在此必須有I,J兩個變量,因為使用二進制保存文件時,
J = J + 1 '從1開始到后面,中間如有間隔就會出現亂碼
End If
Next
Close #iFreefile
Kill gsPath & "data.dat"
Name gsPath & "temp.dat" As gsPath & "data.dat"
riji.txtDate = ""
riji.txtMemo = ""
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -