Solved

SSIS Script Task: Failing at the end of a Loop and not sure why

Posted on 2011-03-21
4
519 Views
Last Modified: 2012-05-11
I finally found a way to loop through a directory to get the most current file from a directory. Now, after it goes through the loop and moves to the End If part of the statment, it ends with failure. Here is a copy...please help...am I missing something? (please note the MsgBox are only there for debugging this process)
-------------------------------------------------------------------------------------
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO ' ADDED

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
      Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

      Enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
      End Enum
    Public Sub Main()
        Try
            'GET SSIS Variables
            Dim strFolder As String = "\\HSFTPSRV\FTPDATA\Patriot\"
            Dim strUpdatedFolder As String = "\\HSNAS01\FileServer\Clients_Data\CLIENTS\PATRIOT\MED\PreCerts\"
            Dim files() As String = System.IO.Directory.GetFiles(strFolder, "*.*")
            Dim FC As Integer = 0

            Dim strOriginalFile As String = files.GetValue(FC).ToString   'returns the value of first file name list
            Dim dt As DateTime = File.GetCreationTime(strOriginalFile)

            Dim PreCertFile As String
            Dim NewFileName As String
            Dim PreRawFile As String

            MsgBox(strOriginalFile)
            MsgBox(dt)

            If Not (DateTime.Now.Subtract(dt).TotalDays < 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                For Each strOriginalFile In strFolder
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                    MsgBox(strOriginalFile)
                    MsgBox(dt)
                Next
            End If

            MsgBox(strOriginalFile)

            PreCertFile = strOriginalFile
            NewFileName = strOriginalFile = Replace(strOriginalFile, ".TXT", "") + ".TXT"
            PreRawFile = Replace(strOriginalFile, strFolder, strUpdatedFolder)

            MsgBox(strOriginalFile)
            MsgBox(PreCertFile)
            MsgBox(NewFileName)
            MsgBox(PreRawFile)

            'Create the file processed in the new directory
            'File.Create(PreRawFile)

            'GENERATE an Information Event
            Dts.TaskResult = ScriptResults.Success
            'Dts.Events.FireInformation(10000, "Script", "Texfile updated.", "", 0, False)

        Catch ex As Exception
            Dts.TaskResult = ScriptResults.Failure
            Dts.Events.FireError(20000, "Script", "Error description.", "", 0)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class-------------------------------------------------------------------------------------
0
Comment
Question by:RicS77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 25

Expert Comment

by:TempDBA
ID: 35182721
Decrease the loop by 1 and handle the last one some other way.
0
 

Author Comment

by:RicS77
ID: 35183903
Not sure I follow...
What about this?

   If Not (DateTime.Now.Subtract(dt).TotalDays < 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                For Each strOriginalFile In strFolder
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                Next
            Else
                PreCertFile = strOriginalFile
                NewFileName = strOriginalFile = Replace(strOriginalFile, ".TXT", "") + ".TXT"
                PreRawFile = Replace(strOriginalFile, strFolder, strUpdatedFolder)
            End If
0
 

Accepted Solution

by:
RicS77 earned 0 total points
ID: 35184206
Figured it out using this instead.

       Dim BGN As Integer = 0
            Do While BGN = 0
                If (DateTime.Now.Subtract(dt).TotalDays > 1) And Left(Right(strOriginalFile, 24), 4) = "TMCS" Then
                    BGN = 0
                    FC = FC + 1
                    strOriginalFile = files.GetValue(FC).ToString
                    dt = File.GetCreationTime(strOriginalFile)
                Else : BGN = 1
                End If
            Loop
0
 

Author Closing Comment

by:RicS77
ID: 35221272
Found the solution to the problem before receiving an approved solution from EE.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question