Print Page | Close Window

Crystal Report Formula Not Working

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21529
Printed Date: 20 Apr 2024 at 1:20am


Topic: Crystal Report Formula Not Working
Posted By: Brinda
Subject: Crystal Report Formula Not Working
Date Posted: 08 Jun 2015 at 9:19pm
Hi, I writing custom function in class. i want to use that custom class in crystal report formula but its not possible so i write custom function in crystal report same as that class function. class function working in windows application perfectly but in crystal report formula not working...

In class Code

public static string CropWholeWords(this string value, int length, HashSet<char> nonWordCharacters)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (length < 0)
            {
                throw new ArgumentException("Negative values not allowed.", "length");
            }

            if (nonWordCharacters == null)
            {
                nonWordCharacters = DefaultNonWordCharacters;
            }

            if (length >= value.Length)
            {
                return value;
            }
            int end = length;

            for (int i = end; i > 0; i--)
            {
                if (value.IsWhitespace())
                {
                    break;
                }

                if (nonWordCharacters.Contains(value)
                    && (value.Length == i + 1 || value[i + 1] == ' '))
                {
                    break;
                }
                end--;
            }

            if (end == 0)
            {
                end = length;
            }

            return value.Substring(0, end);
        }

Crystal report Custom Function Code

function (stringVar ABC,numberVar leng,stringVar deli)
(
    stringVar Anss;
    numberVar end := leng;
    numbervar i;
        (
            if(ABC = "") then
            (
            Anss :="";
            )
            else if(leng < 0) then
            (
            Anss :="";
            )
            else if(leng >= Length(ABC)) then
            (
            Anss := ABC;
            )
        );

       
        for i := end to 1 do
        (
            (
                if (ABC = ' ' or ABC = 'n' or ABC = 't') then
                (
                    Exit for
                )
            );
            (
                if (ABC = deli and (Length(ABC) = i + 1 or ABC[i + 1] = ' ')) then
                (
                    Exit for
                )
            );
            end := end - 1;
        );

        (
            if(end = 0) then
            (
            end := leng;
            )
        );

    Anss := mid(ABC,1,end);
)

what mistake i did in crystal report formula. i m new to crystal report



-------------
Thanks & Regards



Replies:
Posted By: kevlray
Date Posted: 09 Jun 2015 at 7:32am
I am not sure that you want to change the value of end in your for loop.  You should just be able to do a "for i := end to 1 step -1 do".

I am not sure what you are trying to accomplish with the code.  Do you get an error or incorrect results?



Print Page | Close Window