Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005-2015 : Writing Code
Message Icon Topic: Crystal Report Formula Not Working Post Reply Post New Topic
Author Message
Brinda
Newbie
Newbie
Avatar

Joined: 27 Nov 2011
Online Status: Offline
Posts: 7
Quote Brinda Replybullet Topic: Crystal Report Formula Not Working
    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
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1428
Quote kevlray Replybullet 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?
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.