'歡迎你下載使用本代碼,本份代碼由程式太平洋提供下載學習之用
'聲明:
'1.本站所有代碼的著作權歸原作者所有,如果你使用了在本站下載的原始碼
' 引起的一切糾紛(後果)與本站無關,請您尊重原作者的勞動成果!
'2.若本站在代碼上有侵權之處請您與站長聯絡,站長會及時更正。
'中國代碼網:http://www.daima.com.cn
'程式太平洋:http://www.5ivb.net
'email:dapha@etang.com
'copyright 2001-2005 by www.5ivb.net
'整理時間:2004-8-9 3:32:48
option explicit
public objconn as new adodb.connection
public m_connstring as string
private function exists(byval str_filename as string, _
byval int_val as vbfileattribute) as boolean
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : exists
' description: [判斷檔案或目錄是否存在]
' created by : ronggang (zhouronggang@163.com)
' date-time : 2004-8-9-2:31:45
'
' parameters : str_filename (string)
' int_val (vbfileattribute)
'--------------------------------------------------------------------------------
on error resume next
if len(str_filename) = 0 then
exists = false
exit function
end if
if int_val <> vbdirectory then '如果不是目錄
'如果為空白表示檔案不存在
if dir(str_filename) = "" then
exists = false
else
exists = true
end if
else
if dir(str_filename, vbdirectory) = "" then
exists = false
else
exists = true
end if
end if
end function
public sub binvalue(byval strfilename as string, byref objfield as field)
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : binvalue
' description: [將檔案儲存至資料庫中]
' created by : wangfeng
' date-time : 2004-8-9-2:20:37
'
' parameters : strfilename (string)
' objfield (field)
'--------------------------------------------------------------------------------
'此方法需要做錯誤處理,以防檔案己開啟
dim objstream as stream
if not exists(strfilename, vbnormal) then '如果檔案不存則拋出異常
err.raise 50001, "dbfile", "檔案不存在!"
exit sub
end if
set objstream = new adodb.stream
with objstream
.type = adtypebinary
.open
.loadfromfile strfilename
objfield.value = .read
end with
set objstream = nothing
end sub
public function binvalue2file(byval strfilename as string, byref objfield as field, optional overwrite as boolean = false) as boolean
'--------------------------------------------------------------------------------
' project : mycodelibrary 1.5
' procedure : binvalue2file
' description: [將資料庫中的位元據儲存為檔案]
' created by : wangfeng
' date-time : 2004-8-9-2:22:33
'
' parameters : strfilename (string) 目標檔案
' objfield (field) 資料欄位名
' overwrite (boolean = false) 是否覆蓋現有存在的檔案
' true 覆蓋 false(預設)不存在時儲存
'--------------------------------------------------------------------------------
on error goto errorhander
dim objstream as stream
dim returnmsg as vbmsgboxresult
set objstream = new adodb.stream
with objstream
.type = adtypebinary
.open
.write objfield.value
if overwrite then
.savetofile strfilename, adsavecreateoverwrite
else
.savetofile strfilename, adsavecreatenotexist
end if
end with
binvalue2file = true '儲存成功返回true
101:
set objstream = nothing
exit function
errorhander:
binvalue2file = false
goto 101
end function
public function getfilename(byval strpathfilename) as string
dim ipos as long
ipos = vba.instrrev(strpathfilename, "\")
getfilename = mid(strpathfilename, ipos + 1)
end function
public function getpathname(optional strpathname as string) as string
'sfilename = mid(getpathname, ipos + 1)
dim ipos as long
ipos = vba.instrrev(strpathname, "\")
getpathname = mid(strpathname, 1, ipos)
end function