'读取缓存文件的内容
Public function ReadFile
if mfso.FileExists(mfullfile) then
'如果存在缓存文件
if mrefreshtime <> -1 then '需要刷新
Set mopenfile=mfso.getfile(mfullfile)
dim moditime
'获得缓存文件的最后修改时间
moditime = mopenfile.DateLastModified
dim t1,t2
t1 = TimeToSecond(Now())
t2 = TimeToSecond(moditime)
if (t1-t2) > mrefreshtime then
'如果超过缓存有效时间,设置mhaserror
mhaserror = -2
ReadFile = ""
Set mOpenFile=nothing
exit function
end if
Set mOpenFile=nothing
end if
'存在缓存文件,而且没有超过有效时间
Set mopenfile = mfso.OpenTextFile(mfullfile)
ReadFile = mopenfile.readall
set mopenfile = nothing
else
mhaserror = -1
ReadFile = ""
end if
End function
'保存缓存文件的内容
Public sub WriteFile(temps)
Application.Lock '读取缓存文件的内容
Set mopenFile=mfso.OpenTextfile(mfullfile,2,true) 'true为不存在自行建立
mopenFile.writeline(temps)
Set mOpenFile=nothing
Application.UnLock
End sub
End Class
|