'///
'csv < - >mdb convert tool
'written by griefforyou
'///
option explicit
private sub command1_click()
on error goto errhandler
commondialog1.filename = ""
commondialog1.cancelerror = true
commondialog1.filter = "csv file(*.csv;*.txt)|*.csv;*.txt"
commondialog1.showopen
if commondialog1.filename <> "" then
text1.text = commondialog1.filename
end if
exit sub
errhandler:
msgbox "error:" & err.description, vbcritical, "error"
end sub
private sub command2_click()
on error goto errhandler
commondialog1.filename = ""
commondialog1.cancelerror = true
commondialog1.filter = "access file(*.mdb)|*.mdb"
commondialog1.showopen
if commondialog1.filename <> "" then
text2.text = commondialog1.filename
end if
exit sub
errhandler:
msgbox "error:" & err.description, vbcritical, "error"
end sub
private sub command3_click()
if option1.value = true then
if dir(text1.text) = "" then
msgbox "csv檔案不存在!", vbcritical, "錯誤"
exit sub
end if
if csv2mdb(text1.text, text2.text) = true then
msgbox "匯入表成功!", vbinformation, "提示"
end if
else
if dir(text2.text) = "" then
msgbox "csv檔案不存在!", vbcritical, "錯誤"
exit sub
end if
if mdb2csv(text2.text, text1.text, "book1") then
msgbox "匯出csv成功!", vbinformation, "提示"
end if
end if
end sub
private function mdb2csv(mdbfilename as string, csvfilename as string, tablename as string) as boolean
on error goto errhandler
dim adoconn as new adodb.connection
dim adors as new adodb.recordset
dim ret as long
dim strcn as string, strcsvline as string
dim i as integer, j as integer
dim filenum as integer
mdb2csv = false
if dir(csvfilename) <> "" then
ret = msgbox("csv檔案己存在,是否覆蓋?", vbokcancel + vbquestion, "提示")
if ret = vbok then
kill csvfilename
else
exit function
end if
end if
strcn = "provider=microsoft.jet.oledb.4.0;data source=" & mdbfilename
adoconn.connectionstring = strcn
adoconn.open
adors.open tablename, adoconn, adopenkeyset, adlockoptimistic
if adors.eof then
adors.close
set adors = nothing
adoconn.close
set adoconn = nothing
exit function
end if
filenum = freefile
open csvfilename for output as filenum
for i = 0 to adors.fields.count - 1
if strcsvline = "" then
strcsvline = adors.fields(i).name
else
strcsvline = strcsvline & "," & adors.fields(i).name
end if
next
print #filenum, strcsvline
while not adors.eof
strcsvline = ""
for i = 0 to adors.fields.count - 1
if strcsvline = "" then
strcsvline = adors.fields(i)
else
strcsvline = strcsvline & "," & adors.fields(i)
end if
next
print #filenum, strcsvline
adors.movenext
wend
close filenum
adors.close
set adors = nothing
adoconn.close
set adoconn = nothing
mdb2csv = true
exit function
errhandler:
msgbox "error:" & err.description, vbcritical, "error"
end function
private function getfilename(filename as string) as string
dim strtemp as string
strtemp = mid(filename, instrrev(filename, "/") + 1)
getfilename = left(strtemp, len(strtemp) - 4)
end function
日期轉換程式
前兩天看到了一道題 怎麼樣把1990年11月24日轉換成為 一九九零年十一月二十四日 我雖然做出來了,但是感覺自己做的 不是很好,請各位大蝦給予指點 using system using system.collections.generic using system.linq using syste...
注釋轉換程式
這個程式的目的是 把c注釋全部轉換為c 注釋 程式有以下幾個狀態 1 無狀態 的正文部分2 c狀態 注釋方式為c注釋3 c 狀態 注釋方式為c 注釋4 end 結束狀態 這幾種狀態的關係 首先我們要開啟input.c檔案,對這個檔案內部的檔案進行讀取,然後處理,否則直接提示使用者有錯誤。接下來,我們...
小程式 轉換
二進位制字串轉整數 二進位制字串轉整數 如 01111111 127 function binarystrtobyte binarystr var len,re 0 len binarystr.length if len 4 len 8 return parseint binarystr,2 將整數...