dbTalk Databases Forums  

Looping in ActiveX

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Looping in ActiveX in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Matt Cannen
 
Posts: n/a

Default Looping in ActiveX - 09-02-2003 , 12:59 PM








Ok,
I have my activex script that can loop through and remove certain
file extensions that I don't but when it completes that section it
doesn't allow the files left to process. It stops my dts with a success
leaving the other process steps as not run. I am trying to find a
better solution to this existing problem as instead of loop through the
enter directory and working with the last file it comes to I want it to
work with the first file and if it meets the a.dbf,c.dbf,s.dbf,t.dbf
then I want it to process those steps other wise delete anyfile that
doesn't have those extensions.

Code below...



Function Main()

Dim pkg
Dim ConTextFileST
Dim ConTextFileTR
Dim ConTextFileDB
Dim ConTextFileDB2
Dim stpEnterLoopST
Dim stpEnterLoopTR
Dim stpEnterLoopDB
Dim stpEnterLoopDB2
Dim fso
Dim fil
Dim fold
Dim stpFinished

'Set Package reference
set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

'Our Pump Steps
set stpEnterLoopST = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpEnterLoopTR = pkg.Steps("DTSStep_DTSDataPumpTask_2")
set stpEnterLoopDBA = pkg.Steps("DTSStep_DTSDataPumpTask_3")
set stpEnterLoopDBC =
pkg.Steps("DTSStep_DTSDataPumpTask_4")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")


stpEnterLoopDBA.DisableStep = TRUE
stpEnterLoopDBC.DisableStep = TRUE
stpEnterLoopST.DisableStep = TRUE
stpEnterLoopTR.DisableStep = TRUE
stpFinished.DisableStep = TRUE


if ShouldILoop = True THEN

if DTSGlobalVariables("gv_FileExtension").Value = "dbf" then

select case right(DTSGlobalVariables("gv_FileFullName").Value, 5)

case "a.dbf"
'If fso.FileExists(DTSGlobalVariables("gv_temppath") & "tempa.dbf")
= True Then
' fso.DeleteFile (DTSGlobalVariables("gv_temppath") & "tempa.dbf"),
True
'End If

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempa.dbf"
'DTSGlobalVariables("gv_FileName").Value = "tempa.dbf"

stpEnterLoopDBA.DisableStep = False

stpEnterLoopDBA.ExecutionStatus = DTSStepExecStat_Waiting

case "c.dbf"
'If fso.FileExists(DTSGlobalVariables("gv_temppath") & "tempc.dbf")
= True Then
' fso.DeleteFile (DTSGlobalVariables("gv_temppath") & "tempc.dbf"),
True
'End If

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempc.dbf"
DTSGlobalVariables("gv_FileName").Value = "tempc.dbf"

stpEnterLoopDBC.DisableStep = False


stpEnterLoopDBC.ExecutionStatus = DTSStepExecStat_Waiting

case "s.dbf"
'If fso.FileExists(DTSGlobalVariables("gv_temppath") & "temps.dbf")
= True Then
' fso.DeleteFile (DTSGlobalVariables("gv_temppath") & "temps.dbf"),
True
'End If

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "temps.dbf"
DTSGlobalVariables("gv_FileName").Value = "temps.dbf"

stpEnterLoopST.DisableStep = False

stpEnterLoopST.ExecutionStatus = DTSStepExecStat_Waiting

case "t.dbf"
' If fso.FileExists(DTSGlobalVariables("gv_temppath") & "tempt.dbf")
= True Then
' fso.DeleteFile (DTSGlobalVariables("gv_temppath") & "tempt.dbf"),
True
' End If

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempt.dbf"
DTSGlobalVariables("gv_FileName").Value = "tempt.dbf"

stpEnterLoopTR.DisableStep = False

stpEnterLoopTR.ExecutionStatus = DTSStepExecStat_Waiting

End select
End if 'dbf

else
'msgbox "Finished. Disabling DataPumps And Exiting"
'call Archive2Transfer
stpFinished.DisableStep = False
End if

Main = DTSTaskExecResult_Success

End Function

Function ShouldILoop

Dim fso
Dim fil
Dim fold
Dim pkg
Dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation" ).Value)

counter = fold.files.count

' So long as there are text files in the directory carry on

if counter >= 1 then
for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
DTSGlobalVariables("gv_FileName").Value = fso.GetFileName(fil.Path)
DTSGlobalVariables("gv_FileExtension").Value =
fso.GetExtensionName(fil.Path)
DTSGlobalVariables("gv_FileName2").Value = fso.GetFileName(fil.Path)
IF InStr( 1, "a.dbf,c.dbf,s.dbf,t.dbf", StripOffFilePart(
DTSGlobalVariables("gv_FileFullName").Value,".")) Then
'leave this file in trasfer directory to use
Else
'file not used delete and move on
fso.DeleteFile DTSGlobalVariables("gv_FileFullName").Value

end if
ShouldILoop= CBool(True)
Next
else
ShouldILoop = CBool(False)
End if

End Function

Function StripOffFilePart(sFilename,sString)

Dim nExtStartPos

on error resume next
nExtStartPos = InStrRev(sFilename, Trim(sString))
StripOffFilePart = sFilename
If nExtStartPos > 0 Then StripOffFilePart = Trim(Mid(sFilename,
nExtStartPos - 1,60 ))

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #2  
Old   
Yashwant
 
Posts: n/a

Default Looping in ActiveX - 09-02-2003 , 02:03 PM






Hi,
visit www.sqldts.com , might be helpful for you.
regards
yashwant


Quote:
-----Original Message-----


Ok,
I have my activex script that can loop through and
remove certain
file extensions that I don't but when it completes that
section it
doesn't allow the files left to process. It stops my dts
with a success
leaving the other process steps as not run. I am trying
to find a
better solution to this existing problem as instead of
loop through the
enter directory and working with the last file it comes
to I want it to
work with the first file and if it meets the
a.dbf,c.dbf,s.dbf,t.dbf
then I want it to process those steps other wise delete
anyfile that
doesn't have those extensions.

Code below...



Function Main()

Dim pkg
Dim ConTextFileST
Dim ConTextFileTR
Dim ConTextFileDB
Dim ConTextFileDB2
Dim stpEnterLoopST
Dim stpEnterLoopTR
Dim stpEnterLoopDB
Dim stpEnterLoopDB2
Dim fso
Dim fil
Dim fold
Dim stpFinished

'Set Package reference
set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT
("Scripting.FileSystemObject")

'Our Pump Steps
set stpEnterLoopST = pkg.Steps
("DTSStep_DTSDataPumpTask_1")
set stpEnterLoopTR = pkg.Steps
("DTSStep_DTSDataPumpTask_2")
set stpEnterLoopDBA = pkg.Steps
("DTSStep_DTSDataPumpTask_3")
set stpEnterLoopDBC =
pkg.Steps("DTSStep_DTSDataPumpTask_4")
set stpFinished = pkg.Steps
("DTSStep_DTSActiveScriptTask_5")


stpEnterLoopDBA.DisableStep = TRUE
stpEnterLoopDBC.DisableStep = TRUE
stpEnterLoopST.DisableStep = TRUE
stpEnterLoopTR.DisableStep = TRUE
stpFinished.DisableStep = TRUE


if ShouldILoop = True THEN

if DTSGlobalVariables
("gv_FileExtension").Value = "dbf" then

select case right
(DTSGlobalVariables("gv_FileFullName").Value,5)

case "a.dbf"
'If fso.FileExists
(DTSGlobalVariables("gv_temppath") & "tempa.dbf")
= True Then
' fso.DeleteFile
(DTSGlobalVariables("gv_temppath") & "tempa.dbf"),
True
'End If

fso.MoveFile
DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempa.dbf"
'DTSGlobalVariables
("gv_FileName").Value = "tempa.dbf"


stpEnterLoopDBA.DisableStep = False


stpEnterLoopDBA.ExecutionStatus =
DTSStepExecStat_Waiting
Quote:
case "c.dbf"
'If fso.FileExists
(DTSGlobalVariables("gv_temppath") & "tempc.dbf")
= True Then
' fso.DeleteFile
(DTSGlobalVariables("gv_temppath") & "tempc.dbf"),
True
'End If

fso.MoveFile
DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempc.dbf"
DTSGlobalVariables
("gv_FileName").Value = "tempc.dbf"


stpEnterLoopDBC.DisableStep = False



stpEnterLoopDBC.ExecutionStatus =
DTSStepExecStat_Waiting
Quote:
case "s.dbf"
'If fso.FileExists
(DTSGlobalVariables("gv_temppath") & "temps.dbf")
= True Then
' fso.DeleteFile
(DTSGlobalVariables("gv_temppath") & "temps.dbf"),
True
'End If

fso.MoveFile
DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "temps.dbf"
DTSGlobalVariables
("gv_FileName").Value = "temps.dbf"

Quote:
stpEnterLoopST.DisableStep
= False


stpEnterLoopST.ExecutionStatus =
DTSStepExecStat_Waiting
Quote:
case "t.dbf"
' If fso.FileExists
(DTSGlobalVariables("gv_temppath") & "tempt.dbf")
= True Then
' fso.DeleteFile
(DTSGlobalVariables("gv_temppath") & "tempt.dbf"),
True
' End If

fso.MoveFile
DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_temppath") & "tempt.dbf"
DTSGlobalVariables
("gv_FileName").Value = "tempt.dbf"

stpEnterLoopTR.DisableStep
= False


stpEnterLoopTR.ExecutionStatus =
DTSStepExecStat_Waiting
Quote:
End select
End if 'dbf

else
'msgbox "Finished. Disabling DataPumps
And Exiting"
'call Archive2Transfer
stpFinished.DisableStep = False

End if

Main = DTSTaskExecResult_Success

End Function

Function ShouldILoop

Dim fso
Dim fil
Dim fold
Dim pkg
Dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT
("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables
("gv_FileLocation").Value)

counter = fold.files.count

' So long as there are text files in the directory
carry on

if counter >= 1 then
for each fil in fold.Files
DTSGlobalVariables
("gv_FileFullName").Value = fil.path
DTSGlobalVariables
("gv_FileName").Value = fso.GetFileName(fil.Path)
DTSGlobalVariables
("gv_FileExtension").Value =
fso.GetExtensionName(fil.Path)
DTSGlobalVariables
("gv_FileName2").Value = fso.GetFileName(fil.Path)
IF InStr( 1, "a.dbf,c.dbf,s.dbf,t.dbf",
StripOffFilePart(
DTSGlobalVariables("gv_FileFullName").Value,".")) Then
'leave this file in
trasfer directory to use
Else
'file not used delete and
move on
fso.DeleteFile DTSGlobalVariables
("gv_FileFullName").Value

end if
ShouldILoop= CBool(True)
Next
else
ShouldILoop = CBool(False)
End if

End Function

Function StripOffFilePart(sFilename,sString)

Dim nExtStartPos

on error resume next
nExtStartPos = InStrRev(sFilename, Trim(sString))
StripOffFilePart = sFilename
If nExtStartPos > 0 Then StripOffFilePart = Trim
(Mid(sFilename,
nExtStartPos - 1,60 ))

End Function


*** Sent via Developersdex http://www.developersdex.com
***
Don't just participate in USENET...get rewarded for it!
.


Reply With Quote
  #3  
Old   
Matt Cannen
 
Posts: n/a

Default Re: Looping in ActiveX - 09-02-2003 , 04:10 PM



Thanks for the reply and I have visited the SQLDTS.com in the past and
it has helped me greatly. Unfortuneatly this was a little more in depth
of a question than there example delt with. I was able to figure this
out on my own. But again thank you for responding with some helpful
direction.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.