大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 通用数据链接文件 (*.UDL) 的创建

通用数据链接文件 (*.UDL) 的创建

时间: 2021-07-31 作者:daque

援用 microsoft ole db service component 1.0 type libraryoption explicitprivate sub command1_click()dim x as new msdasc.datalinksx.hwnd = me.hwnddim s as stringon error goto errorhandlers = x.promptnewon error goto 0if vba.len(vba.trim(s & "")) > 0 thendim commondialog1 as new mscomdlg.commondialogcommondialog1.defaultext = ".udl"commondialog1.filter = "通用数据链接文献 (*.udl)|*.udl"commondialog1.dialogtitle = "生存为通用数据链接文献"commondialog1.flags = cdlofnoverwritepromptcommondialog1.cancelerror = trueon error goto errorhandlercommondialog1.showsaveon error goto 0s = "[oledb]" & vbcrlf _& "; everything after this line is an ole db initstring" & vbcrlf _& s & vbcrlfdim bytesbuffer() as bytebytesbuffer = vba.strconv(vba.strconv(s, vbunicode), vbfromunicode)dim i as longredim bytesbuffer0(1) as bytebytesbuffer0(0) = 255 解释:&hffbytesbuffer0(1) = 254 解释:&hfeif vba.len(vba.trim(vba.dir(commondialog1.filename))) > 0 thenvba.kill commondialog1.filenameend ifon error goto errorhandleri = vba.freefileopen commondialog1.filename for binary access write as #iput #i, , bytesbuffer0put #i, , bytesbufferclose #ion error goto 0if vba.msgbox("test?", vbyesno) = vbyes thendim adoconnection as new adodb.connectionadoconnection.open "file name=" & commondialog1.filenamevba.msgbox "ok!"end ifend ifexit suberrorhandler:if err.number <> 91 and err.number <> 32755 thenvba.msgbox err.number & ":" & vbcrlf & err.descriptionend ifend subprivate sub command2_click()dim commondialog1 as new mscomdlg.commondialogcommondialog1.defaultext = ".udl"commondialog1.filter = "通用数据链接文献 (*.udl)|*.udl"commondialog1.dialogtitle = "打开明用数据链接文献"解释:commondialog1.flags = cdlofnoverwritepromptcommondialog1.cancelerror = trueon error goto errorhandlercommondialog1.showopenon error goto 0if vba.len(vba.trim(vba.dir(commondialog1.filename))) > 0 thenvba.msgbox getconnectionstringfromudl(commondialog1.filename)end ifexit suberrorhandler:if err.number <> 91 and err.number <> 32755 thenvba.msgbox err.number & ":" & vbcrlf & err.descriptionend ifend subpublic function getconnectionstringfromudl(udlfilename as string) as stringif vba.len(vba.trim(vba.dir(udlfilename & ""))) > 0 thendim bytesbuffer() as byteredim bytesbuffer(vba.filelen(udlfilename) - 133) as bytedim i as longi = vba.freefileopen udlfilename for binary access read as #iget #i, 129, bytesbufferclose #igetconnectionstringfromudl = vba.trim(vba.strconv(vba.strconv(bytesbuffer, vbfromunicode), vbunicode))end ifend function

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.