Hello,
I am revisting a problem I had previously and still have no luck in resolving it. (I am using v9.2)
I am setting Named References from column data in a Wingrid. When a try to set a Date as a named reference, the calculations do not work - I notice that the formula result (when setting the Named Reference Formula) is returning as an error.
Here is an excerpt from my code. You will see that the debug line is always hit. The Message returned is Incorrect type of argument or operand.
If uds.Rows(iRow).Item(iLoop) IsNot Nothing Then
Dim dtDate As Date
dtDate = CType(uds.Rows(iRow).Item(iLoop), Date)
Calcmanager.NamedReferences.Item(sKey).Formula = " DATEVALUE( " & Chr(34) & dtDate.ToString("MM/dd/yyyy hh:mm tt") & Chr(34) & " )"
If Calcmanager.NamedReferences.Item(sKey).FormulaResult.IsError Then
Debug.WriteLine(CType(Calcmanager.NamedReferences.Item(sKey).FormulaResult.Value, Infragistics.Win.CalcEngine.UltraCalcErrorValue).Message)
End If
I even tried simply hard coding a date like this line:
Calcmanager.NamedReferences.Item(sKey).Formula = " DATE( 1,1,2010)"
But still I get the same error.
Can you please help with setting this Named Reference.
Regards and Thanks.
Greg.
Hi Greg,
I tried this out like and I get the same results. But checking the FormulaResult immediately after adding the NamedReference will not work since the CalcManager performs it's calculations asynchronously.
The calculation hasn't been performed yet.
Just to make sure this is the case, I added a line to the bottom of your code where I set the formula of a Label control to the name of the NamedReference and this label displays the date correctly.
Mike,
Thanks for the response. It led to me to the solution...
I had to place the line
Calcmanager.ReCalc(-1)
After setting all the Named References, and before using them in a formula. This is obviously needed to tell the CalcEngine to process the Named Reference formulas. (Maybe something should be added to the manuals)
Interestingly, this was not needed for numeric, text or other field types, only for Dates.
Anyway this solved the problem. (and maybe help others hitting this issue)
Thanks.
Mike Saltzman"] Hi Greg, I tried this out like and I get the same results. But checking the FormulaResult immediately after adding the NamedReference will not work since the CalcManager performs it's calculations asynchronously. The calculation hasn't been performed yet. Just to make sure this is the case, I added a line to the bottom of your code where I set the formula of a Label control to the name of the NamedReference and this label displays the date correctly.