August 20, 2003 at 10:06 am
It is my understanding that global variables that are set by a package e.g. within an ActiveX Script Task, are removed after the package has finished executing and cannot be seen in the package/properties window.
Is there anyway I can overide this within a package? I want to dynamically name global variables according to user input and call them next time the package is run. Obviously if the variables are not saved after the end of the package then this is not possible.
If I cannot override this then the other option is to loop through each of the global variables and save each of their names and values to a recordset or file. Does anyone have any code that will do this within an activex task? I know how to write to a file (I'm no good with ado recordsets) but I do not know how to loop through the global variables.
Can anyone help?
August 25, 2003 at 12:00 pm
This was removed by the editor as SPAM
August 27, 2003 at 12:18 am
You cannot save the values of the global variables from run to run.
As for looping through global variables:
Dim objPackage
Set objPackage = DTSGlobalVariables.Parent
For each objGlVar in objPackage.GlobalVariables
Set objGVProperties = objGlVar.Properties
strName = objGVProperties("Name").Value
strValue = objGVProperties("Value").Value
' your stuff can be inserted
' here
NEXT
August 27, 2003 at 1:21 am
Thanks a lot, using a little bit of your suggestion I have managed a workaround. This involves two activeX script tasks. The first loads the variables and is run before any other tasks. The second saves them and is run after every other task. It seems to work very well. This is the code in the first....
'Load Variables
Function Main()
set pkg = DTSGlobalVariables.Parent
set fso = CreateObject("Scripting.FileSystemObject")
set file=fso.opentextfile("E:\gvsave.txt",1,False) '**Load in previous runs global variables
While Not file.AtEndOfStream '**Take two lines at a time (gv's name and value) until end of file
gv_name = file.readline
gv_value = file.readline
DTSGlobalVariables(""&gv_name)= gv_value
Wend
file.close '** Clean up
Main = DTSTaskExecResult_Success
End Function
.........and the second.......
'Save Variables
Function Main()
set pkg = DTSGlobalVariables.Parent
set fso = CreateObject("Scripting.FileSystemObject")
set file=fso.opentextfile("E:\gvsave.txt",2,True)
For Each gv in pkg.Globalvariables
file.write gv.name & vbcrlf
file.write gv.value & vbcrlf
next
file.close
Main = DTSTaskExecResult_Success
End Function
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply