VB中如何绑定资源文件

来源:互联网 发布:tightvnc软件怎么使用 编辑:程序博客网 时间:2024/04/28 13:01

今天在做项目的过程中遇到需要在VB程式中提供用户Excel模板下载的功能。这里采用的方式是将Excel作为Vb程式的资源文件捆绑,用程式实现读取资源文件并下载该文件。具体实现如下:

1:选择Add-Ins菜单中的Add-In Manager

2:选择VB 6 Resource Editor选项,点击OK

3:此时在快捷栏中就会初夏VB Resource Editor按钮,点击按钮进入Resource编辑窗口

4:增加Resource文件到VB程式托管,此处新增一个自定义文件类型Excel

5:程式中实现Download的代码如下:

    Dim bXLS() As Byte
    Dim objStream As New ADODB.Stream
   
    dlgXLSFile.CancelError = False
    dlgXLSFile.ShowSave
   
    If Trim$(dlgXLSFile.filename) <> "" Then
       
        ''''Load Resource
        bXLS = LoadResData(101, "CUSTOM")
   
        ''''Set Property
        objStream.mode = adModeReadWrite
        objStream.Type = adTypeBinary
       
        objStream.Open
        objStream.Write bXLS
       
        objStream.Position = 0
        objStream.Type = adTypeText
        objStream.Charset = "BIG5"
       
        ''''Save to local
        objStream.SaveToFile dlgXLSFile.filename, adSaveCreateOverWrite
       
        objStream.Close
        Set objStream = Nothing
       
        MsgBox "Download File OK!", vbInformation, "SCM Information"
   
    End If

值此就会实现Resource的绑定与下载功能。

原创粉丝点击