September 25, 2009 at 5:54 am
I have 27 files that need to be processed daily. The vendor that is sending me the files will send a done file for each file once they have finished transmitting the data file. I need to keep looking for the 27 Done files and then trigger the rest of my package to execute. I was thinking a foreach loop within a for loop, but I haven't found a way to pass a counter variable between the 2 looping containers.
I have added a script task to my for loop with the following code, but I can't get the local counter variable to not reset for each new file within the foreach loop
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Dim FileCount As Integer
Public Sub Main()
MsgBox("Before: " & FileCount)
FileCount += 1
MsgBox("After: " & FileCount)
End Sub
End Class
September 25, 2009 at 7:29 am
How are you scoping the variable you are passing?
I believe it should be scoped to the outer ForEach container or to the package.
September 25, 2009 at 7:32 am
I'm simply trying to increment the counter, but it resets to zero with each new file. I'm using the file enumerator in the foreach loop and it's just the file name. Can I add more variables to the foreach loop?
September 25, 2009 at 7:54 am
Try reading in the variable into your script, adding 1 to it, and writing it back out. Then the new value will be preserved.
September 25, 2009 at 8:39 am
I have added the varFileCount to the readwritevariable, and I'm updating the counter using this code
Dim FileCount As Integer
FileCount += 1
Dts.Variables("varFileCount").Value = FileCount
I still can't get the varFileCount variable to not reset with each iteration of the foreach loop. What am I doing wrong?
September 25, 2009 at 9:09 am
Set FileCount to the value in varFileCount. Then add one to it. Your present approach keeps adding 1 to zero.
September 25, 2009 at 9:25 am
I'm getting an error that says Option Strict On disallows implicit conversions from 'Object' to 'Integer'.
How do I convert the object to an integer?
September 25, 2009 at 9:31 am
This did the trick
FileCount = CType(Dts.Variables("varFileCount").Value, Integer)
FileCount += 1
Dts.Variables("varFileCount").Value = FileCount
thanks for all the help
September 25, 2009 at 9:37 am
Happy to help!
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply