using functions within DTS Script

  • I'm still at the banging-head-against-wall stage when it comes to SQL/DTS etc.

    I'm trying to perform the following transformation but am getting a missing ')' error on line 21 (the Function getValue line...

    The VB parses in my head, so am I doing something fundamentally wrong here?

    Also - the destination fields for the Col5, 6, 7 & 8 is a Money field. should I return the value from getValue as a Double, String, Currency or Money data type?

    Regards

    Paul

    '**********************************************************************

    ' Visual Basic Transformation Script

    ' Copy each source column to the

    ' destination column

    '************************************************************************

    Function Main()

    DTSDestination("CoNo") = DTSSource("Col001")

    DTSDestination("SKU") = DTSSource("Col002")

    DTSDestination("AccountCode") = DTSSource("Col003")

    DTSDestination("DelSeq") = DTSSource("Col004")

    DTSDestination("ListPrice") = getValue(DTSSource("Col005"))

    DTSDestination("Discount") = getValue(DTSSource("Col006"))

    DTSDestination("NetPrice") = getValue(DTSSource("Col007"))

    DTSDestination("ChannelDiscount") = getValue(DTSSource("Col008"))

    Main = DTSTransformStat_OK

    End Function

    Function getValue(strValue as String) As Double

    ' receives a string as imported from the file

    ' returns a currency value

    If Len(strvalue)=11 Then

    getvalue=Ccur(strvalue)/1000

    Elseif Len(strvalue)=12 And Right(strValue,1)="-" Then

    getvalue=0 - ccur(Left(strValue,11))/1000

    Else

    getvalue=0

    End If

    End Function

  • It's the function declaration that isn't parsing:

    Function getValue(strValue as String) As Double

    You can't declare the return type in VBScript. Functions return Variants. The joy of a non type-safe scripted environment.

     

     

  • many thanks, the hard way is often the best way!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply