blog.Toby

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  130 随笔 :: 2 文章 :: 150 评论 :: 0 Trackbacks

要想在脚本组件中访问包变量,首先必须设置脚本组件2个属性的值,如下
ReadOnlyVariables
ReadWriteVariables
这2值指定了哪些变量可以访问,哪些变量可以改写(如有多个变量则用逗号分隔),如果你没有指定上面2个属性的值,则不能在脚本组件的代码中访问包变量

下面我举一个从文件中加载内容到包变量的一个例子
 1、首先我们定义2个变量 FileName 和 FileContents ,并指定其类型为 String
 2、拖曳一个脚本组件到控制面板上,并设置 ReadOnlyVariables和ReadWriteVariables 属性的值分别为 FileName 、FileContents
 3、设计脚本组件的代码,如下 
 

 Public Sub Main()
         Dim errorInfo As String = ""
         Dim Contents As String = ""
 
         Contents = GetFileContents(Dts.Variables("FileName").Value, errorInfo)
         If errorInfo.Length > 0 Then
             MsgBox(errorInfo, MsgBoxStyle.Critical, "Error")
             Dts.TaskResult = Dts.Results.Failure
         Else
             MsgBox(Contents, MsgBoxStyle.OKOnly, "File contents")
             Dts.Variables("FileContents").Value=Contents
             Dts.TaskResult = Dts.Results.Success
         End If
  End Sub

 Public Function GetFileContents(ByVal filePath As String, Optional ByVal ErrorInfo As String = "") As String
        Dim strContents As String
        Dim objReader As StreamReader
        Try
            objReader = New StreamReader(filePath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            Return strContents
        Catch Ex As Exception
            ErrorInfo = Ex.Message
        End Try
    End Function

posted on 2007-10-14 20:49 渠上月 阅读(302) 评论(0)  编辑  收藏 所属分类: VS 2005

只有注册用户登录后才能发表评论。


网站导航: