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. Image for the cookie policy date

Writing a custom logical function

How would I write a function who''s return value can be evaluated by the IF statement you provide ? I''m a little confused, since the signature for custom functions always returns a string. Is the string TRUE and FALSE actually evaluated as a logical values or is there a boolean type you use internally for this thats not available for custom functions ?

4 Replies

AD Administrator Syncfusion Team March 25, 2005 02:33 AM UTC

The string TRUE is recognized as the true logical value. So, if you have the formula if(TRUE,1,0) you will see 1 as the calculated value. In this sample, \Syncfusion\Essential Suite\3.0.1.0\Windows\Calculate.Windows\Samples\DataGridCalculator, if you replace the definition of the custom function with this code,
public string ComputeMymin(string args)
{	
	if(args == "1")
		return "TRUE";
	else
		return "FALSE";
}
you can then type this formula in the textbox = IF(mymin(1),18,20) then you will see 18 displayed.


BK Brad King March 25, 2005 02:57 PM UTC

Interesting. Thanks Clay. Having not used Excel style functions much this seems very strange, but workable. >The string TRUE is recognized as the true logical value. So, if you have the formula > >if(TRUE,1,0) > >you will see 1 as the calculated value. > >In this sample, \Syncfusion\Essential Suite\3.0.1.0\Windows\Calculate.Windows\Samples\DataGridCalculator, if you replace the definition of the custom function with this code, >
>public string ComputeMymin(string args)
>{	
>	if(args == "1")
>		return "TRUE";
>	else
>		return "FALSE";
>}
>
>you can then type this formula in the textbox > >= IF(mymin(1),18,20) > >then you will see 18 displayed.


BK Brad King March 25, 2005 03:21 PM UTC

Actually there is one more issue of confusion for me on this. Is there any difference between "TRUE" and TRUE ? Do all strings need to be in quotes, except TRUE and FALSE ? >The string TRUE is recognized as the true logical value. So, if you have the formula > >if(TRUE,1,0) > >you will see 1 as the calculated value. > >In this sample, \Syncfusion\Essential Suite\3.0.1.0\Windows\Calculate.Windows\Samples\DataGridCalculator, if you replace the definition of the custom function with this code, >
>public string ComputeMymin(string args)
>{	
>	if(args == "1")
>		return "TRUE";
>	else
>		return "FALSE";
>}
>
>you can then type this formula in the textbox > >= IF(mymin(1),18,20) > >then you will see 18 displayed.


AD Administrator Syncfusion Team March 25, 2005 09:09 PM UTC

How are you trying to use Essential Calculate? If you are trying to use CalcQuick, then if you do not use ''extra'' quotes when you set a string into a variable. But you do include the quotes when you use the string in as part of a formula expression. For example, in the \Syncfusion\Essential Suite\3.0.1.0\Windows\Calculate.Windows\Samples\FirstSample Algebraic expression sample, you can enter the letter a as the variable name, and the word test as the variable value and then click Set Variable to set the variable a to be the string test. Then in the Algebraic expression textbox, you would type [a]="test" and press Compute to see this computed value which will be TRUE. If you are using an ICalcData object like one of the DataGrid samples we ship, you could enter just the word test into say cell A3. Then in another cell, you could type = A3="test" to display whether A3 contained test. So, in general, you only need the quotes around strings when you are entering formulas.

Loader.
Live Chat Icon For mobile
Up arrow icon