Monday, March 19, 2012

DTS automatic dat file import

Hi y'all

I'm having some trouble with the following script I use in a
dts-package. I use it to automatically import a dat-file of which the
name changes every day. Today the name f.e. is P0000020.dat, tomorrow
it's P0000021.dat and the day after P0000022.dat etc etc The error I
get is end of instruction expected.
This is the script:

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************

Function Main()
Dim oPkg, oDataPump
Dim sSourceTable, sDestinationTable

' Derive the new table names
sSourceTable ="" & GetName
sDestinationTable = sSourceTable
' Get reference to the DataPump Task
Set oPkg = DTSGlobalVariables.Parent
Set oDataPump = oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask

' Set the new values
oDataPump.SourceObjectName = sSourceTable
oDataPump.DestinationObjectName = "[Test].[test].[tblXafaxOutput]"
' Clean Up
Set oDataPump = Nothing
Set oPkg = Nothing

Main = DTSTaskExecResult_Success
End Function

Function GetName
Dim number, counter, file
counter = 1
number = DTSGlobalVariables("NextNumber").Value
number = number + 1
For counter = 1 To 7 - Len(number)
file = file & "O"
Next teller
file = "P" & file & getal & ".dat"
DTSGlobalVariables("NextNumber").Value = number
GetName = file
End Function

I've used this script before in another dts-package where the
file-name needs to be based up-on the date and it worked just fine.
You can find the script at:
http://groups.google.be/groups?hl=n...l e.com#link10

I hope anyone can help me.
thanx in advance
Piedro

PS I've my english is crap it's because it ain't my mothertongue."Piedro" <pproost@.hotmail.com> wrote in message
news:b7e3650a.0309231319.7d8d0ffa@.posting.google.c om...
> Hi y'all
> I'm having some trouble with the following script I use in a
> dts-package. I use it to automatically import a dat-file of which the
> name changes every day. Today the name f.e. is P0000020.dat, tomorrow
> it's P0000021.dat and the day after P0000022.dat etc etc The error I
> get is end of instruction expected.
> This is the script:
> '************************************************* *********************
> ' Visual Basic ActiveX Script
> '************************************************* ***********************
> Function Main()
> Dim oPkg, oDataPump
> Dim sSourceTable, sDestinationTable
> ' Derive the new table names
> sSourceTable ="" & GetName
> sDestinationTable = sSourceTable
> ' Get reference to the DataPump Task
> Set oPkg = DTSGlobalVariables.Parent
> Set oDataPump = oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
> ' Set the new values
> oDataPump.SourceObjectName = sSourceTable
> oDataPump.DestinationObjectName = "[Test].[test].[tblXafaxOutput]"
> ' Clean Up
> Set oDataPump = Nothing
> Set oPkg = Nothing
> Main = DTSTaskExecResult_Success
> End Function
> Function GetName
> Dim number, counter, file
> counter = 1
> number = DTSGlobalVariables("NextNumber").Value
> number = number + 1
> For counter = 1 To 7 - Len(number)
> file = file & "O"
> Next teller
> file = "P" & file & getal & ".dat"
> DTSGlobalVariables("NextNumber").Value = number
> GetName = file
> End Function
>
> I've used this script before in another dts-package where the
> file-name needs to be based up-on the date and it worked just fine.
> You can find the script at:
http://groups.google.be/groups?hl=n...l e.com#link10
> I hope anyone can help me.
> thanx in advance
> Piedro
>
> PS I've my english is crap it's because it ain't my mothertongue.

The message you get is probably because of the For .. Next loop. In
VBScript, you can't put the counter variable name after Next (as you would
in VB):

For x = 1 To 10
' Do something
Next ' This is OK

For x = 1 To 10
' Do something
Next x ' This is wrong

Simon

No comments:

Post a Comment