|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4,
Visits: 8
|
|
I have a SSIS package with a script task which I would like to calculate the sum of two int32 variables(say "a" and "b", package level var) and store in variable "c". I'm not familiar with VB/.NET and I follow some books' example and wrote the following code: ------- If ((Dts.Variables.Contains("a") = True) And (Dts.Variables.Contains("b") = True)) Then
Dts.Variables("c").Value = Dts.Variables("a").Value + Dts.Variables("b").Value
End If ------- The IDE told me that "Option Strict On prohibits operands of type Object for operator '+'". I don't know also how to set the property of a variable to be readable/writable. Could someone tell me what should I amend to make the script work? Thank you!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 11:02 AM
Points: 1,073,
Visits: 6,321
|
|
The variables would added to the ReadWriteVariables option which is on the same tab where you clicked on Design Script... of the Script Task.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4,
Visits: 8
|
|
| Thanks. I think I've already added those variables to the properties (using the format of "User::a", "User::b", etc, w/o quote), is it right? However, it still shows that error message. Would you mind to teach me the necessary steps to make it work? Or point out the steps that maybe missing? Thank you!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 11:02 AM
Points: 1,073,
Visits: 6,321
|
|
First, the variables would be specified as "a,b,c" (without the quotes).
Second, "Option Strict" is a compiler option that's there to help you from introducing logic errors.
For example, set the type for variable "a" to Boolean and set it to true. Set the type for variable "b" to Int32 and set it to 3. Open the script and add "Option Strict Off" at the top and then run the task. With checking off it will not only run but give you an incorrect result.
To make this work, explicitly convert the variables before adding them.
CInt(DTS.Variables("a").value) + CInt(DTS.Variables("b").value)
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 16, 2011 1:47 AM
Points: 4,
Visits: 8
|
|
|
|
|