We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Need Help With Custom Function with Variables

Thread ID:

Created:

Updated:

Platform:

Replies:

43060 Apr 12,2006 06:54 PM UTC Apr 17,2006 07:07 AM UTC WinForms 3
loading
Tags: Calculate
Ross Russell
Asked On April 12, 2006 06:54 PM UTC

Hi. I''m new to the calc engine and have a question about what''s passed to my custom function. Here''s a chunk of the code: --------------------------------- CalcQuick calculator = new CalcQuick(); calculator["1111"] = "test"; calculator.Engine.AddFunction("SUBSTRING", new CalcEngine.LibraryFunction(CustomFunctions.ComputeSubstring)); string result = calculator.ParseAndCompute("SUBSTRING([1111],1,2)"); -------------------------------------- Now, in my SUBSTRING function, I''m passed "A1,1,2" in the args parm. I see the ''1'' of ''A1'' means the 1st entry in the variable table (by adding more and getting A2, A3, etc.). What''s the proper method for me to get value ("test") from this so I can perform the substring operation on it? Thanks! Ross

Administrator [Syncfusion]
Replied On April 13, 2006 10:03 AM UTC

Hi Ross, Please refer this sample. SUBSTRING.zip Also please refer SingleDataGridForm.cs in the following sample to add new formula to the formula library. C:\Program Files\Syncfusion\Essential Studio\4.1.0.x\windows\Calculate.Windows\Samples\GridDataBoundGridCalculator\ Let us know if this helps. Thanks for choosing and using Syncfusion Products. Best Regards, Jeba

Ross Russell
Replied On April 13, 2006 02:25 PM UTC

Jeba, you''re almost there, thanks! I had the custom function running okay, but I''m wondering about the passing of virtual variables. If, in the SUBSTRING project you created, there was CalcQuick calculator = new CalcQuick(); calculator["1111"] = "test"; and then you called string result = calculator.ParseAndCompute("SUBSTRING([1111],1,2)");, what''s the proper way to get "test" from the variable in the custom function? I get "A1" passed to me in the first SUBSTRING() parameter. Thanks! Ross

Administrator [Syncfusion]
Replied On April 17, 2006 07:07 AM UTC

Hi Ross, Sorry for the delay in response. CalcQuick objects do not expose a row, col data access model but, the CalcEngine requires such a model. So, CalcQuick uses a row, col access model internally but, only exposes using formula Key values to access formulas. The Hashtable serves as the data store for the CalcQuick instance. The keys are the strings that are used to identify formulas and the values are FormulaInfo objects that hold information on each formula or value. If you have source code please debug through the source, GetValueRowCol function in CalcQuick.cs returns the string corresponding to the cell A1. //CalcQuick.cs public object GetValueRowCol(int row, int col) { string key = this.RowsToKeyMap[row].ToString(); string s = this[key].ToString(); if(s != null && s.EndsWith("%") && s.Length > 1) { double d; if(double.TryParse(s.Substring(0, s.Length-1), NumberStyles.Any, null, out d)) { s = (d / 100).ToString(); } } return s; } Here is the modified sample: SUBSTRING.zip Best Regards, Jeba.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;