System.FormatException
I am using the following Script task to dynamically populate the value of a variable. Public Sub Main() ' ' Add your code here ' Set_ArchiveFile(".txt") Dts.TaskResult = ScriptResults.Success End Sub Private Sub Set_ArchiveFile(ByVal Ext As String) Dts.Events.FireInformation(1, "", "Entering Set_ArchiveFile. V_Archive_File: " & Dts.Variables("V_ArchiveFile").Value.ToString, "", 0, False) Dts.Variables("V_ArchiveFile").Value = CStr(Dts.Variables("C_Archive_Path").Value) + _ +"\\" + Strings.Replace(CStr(Dts.Variables("V_ShortName").Value), Ext, "_" + CStr(Dts.Variables("V_Load_ID").Value) + Ext) End Sub " The variables contain values in the following format: C_Archive_Path=E:\Archive V_ShortName=SourcFile.txt V_Load_Id=1001 All variables other then V_Load_Id are string datatypes. I am getting the following error while executing. Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Conversion from string "E:\Archive" to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) --- End of inner exception stack trace --- Please let me any what is wrong with the code?
July 14th, 2011 8:29am

It is hard to the see the code, also it is incomplete. Could you use the </> icon/button to paste the code into a popup window? On the surface it seems variable V_ArchiveFile is not of type stringArthur My Blog
Free Windows Admin Tool Kit Click here and download it now
July 14th, 2011 9:40am

Reposted after adding full code. Double checked to see if any misses but no. V_ArchiveFile is of type String. What I wish to achieve is to have a single variable hold the archive path of multiple files, which is set at runtime using variables populated from entries in database. Is there any other way I can achieve this dynamically without a script? If I use an Expression it works but that wont help in case of Multiple Files.
July 14th, 2011 10:16am

If C_ArchivePath is a string why do have CStr conversion? Seems that it does not like the \ in the path, can you make the \doubled in the variable or put the @ as an escape in the code like: @Dts.Variables("C_Archive_Path").Value Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
July 14th, 2011 10:35am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics