Page 1 of 2

crystal formula used to group

Posted: Mon Feb 10, 2020 5:47 pm
by jgoswalt
I have a formula that I have from a crystal report. Basically I have a database field that contains FirstName a space and LastName. I want to parse this field to get the last name and then use that to group/sort the report. This code is in a crystal formula called SortEmpLName. I then group the report on this field. Below is the original crystal code. How do I do this is Stimulsoft?


global stringvar lname:= "";
local numbervar i;

for i := Length ({AttendSumm.EmplName}) to 1 step -1 do
(
if Mid ({AttendSumm.EmplName},i ,1 ) = " " then
(
lname:= Mid ({AttendSumm.EmplName},i+1 ) + ", " + Left ({AttendSumm.EmplName},i - 1 );
exit for
)
);
lname

Re: crystal formula used to group

Posted: Thu Feb 13, 2020 9:44 pm
by Lech Kulikowski
Hello,

You can use the following expression:
{Substring(AttendSumm.EmplName, AttendSumm.EmplName.IndexOf(" "), AttendSumm.EmplName.Length)}

Thank you.

Re: crystal formula used to group

Posted: Mon Feb 17, 2020 2:45 pm
by jgoswalt
Lech, I need to be able to search backwards, as some employee names have a middle initial. Using your above example I get:
Amy A. Bear
Joe E. Honious
Jack E. Reno
Jason Fray
john Isaacs

Re: crystal formula used to group

Posted: Wed Feb 19, 2020 9:18 pm
by Lech Kulikowski
Hello,

You can use a more complex expression to get the necessary result or prepare an additional column for grouping in data source.

Thank you.

Re: crystal formula used to group

Posted: Tue Feb 25, 2020 2:42 pm
by jgoswalt
Still not sure how to do this? All I seem to get is the function name printing out. Any more help would be appreciated.

Re: crystal formula used to group

Posted: Mon Mar 02, 2020 11:31 am
by Lech Kulikowski
Hello,

You can use the following expression:
{Substring(AttendSumm.EmplName, AttendSumm.EmplName.LastIndexOf(" "), AttendSumm.EmplName.Length)}

Thank you.

Re: crystal formula used to group

Posted: Tue Mar 10, 2020 2:24 pm
by jgoswalt
Example: "Anita A. Smith" or "Mark Brown"

{Substring(AttendSumm.EmplName, AttendSumm.EmplName.LastIndexOf(" "), AttendSumm.EmplName.Length)}

I have tried many variations of the above code and still no luck. It actually needs to be something like this, but this still does not work as it picks up the " " and give you " Smith" or " Brown"

{Substring(AttendSumm.EmplName, AttendSumm.EmplName.LastIndexOf(" "), AttendSumm.EmplName.Length - AttendSumm.EmplName.LastIndexOf(" "))}
or {AttendSumm.EmplName.substring(AttendSumm.EmplName.LastIndexOf(" "), AttendSumm.EmplName.Length - AttendSumm.EmplName.LastIndexOf(" "))}
When I use the above, it gives me the error of:

One or more errors occurred.
c:\Windows\Temp\ya3llnyk.0.cs(465,40) : error CS0103: The name 'substring' does not exist in the current contextc:\Windows\Temp\ya3llnyk.0.cs(465,98) : error CS1061: 'string' does not contain a definition for 'lastindexof' and no extension method 'lastindexof' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)


I also used another string function called instrrev. This works the way I want it to in vb.net, but gives me a similar error to above referencing substring and instrrev.

attendsumm.emplname.Substring(InStrRev(attendsum.emplname, " "), attendsumm.emplname.Length - InStrRev(attendsum.emplname, " "))

Help!! I am sure there is something simple that I am missing.

Re: crystal formula used to group

Posted: Fri Mar 13, 2020 8:32 pm
by Lech Kulikowski
Hello,

Please send us a sample report with test data which reproduces the issue for analysis.

Thank you.

Re: crystal formula used to group

Posted: Mon Mar 23, 2020 1:37 pm
by jgoswalt
I can't really do that. The report and database are in a package called E2-shoptech. I am just modifying one of the reports.

Re: crystal formula used to group

Posted: Mon Mar 23, 2020 4:02 pm
by Lech Kulikowski
Hello,

It is difficult to say something else about the issue without a sample. Please send the request to the E2-shoptech developers.

Thank you.