Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Need to extract repeated text - Looping? Post Reply Post New Topic
Author Message
Jaelle
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote Jaelle Replybullet Topic: Need to extract repeated text - Looping?
     Posted: 14 Oct 2009 at 6:12am
Hello, newbie here.  Forgive me if I don't reply till next week, I only work part-timeSmile
 
 
I have a field of user actions ( {Booking.EditHistoryEventList} ), such as below:

Staff Member NF selected by CW
Client Confirmed with HELEN with Ref : 0909004045. Entered by CW
Booking Edited by CW
Staff Cancelled reason working 3 nights wants two days off by KP staff member was NF
Booking Edited by KP
Name Change Set By KP. Name change was NF
Staff Member GM selected by CW
Booking Edited by CW
Name Change done by CW. Name change was NF
Staff Confirmed By SD
Booking Edited by SD
Booking status set to Complete by Server

I need to extract the lines where all instances of the line starting "Staff Member" appear.

I have tried a While formula:

stringVar NewName := {Booking.EditHistoryEventList};
numberVar i := -1;
numberVar Strlen := length (NewName);
numberVar Result := -1;

while i <= Strlen and Result = -1 do
(
    stringVar Position:= mid (NewName, i, -1);
    if  Position = "Staff Member " then
        Result := i;
    i := i - 1;
);
stringVar NewName2 := mid (NewName, Result+1, (Strlen-Result));
NewName2

But I get the "Start position is less than 1 or not an interger" and it highlights the bold text above.

I have used this formula from a tutorial, without really understanding what it does, so any advice is gratefully recieved.
I am using Crystal 9, reading a Lotus Notes database
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Oct 2009 at 6:38am
mid(str1, start, len) returns a substring from str1, starting at start for len characters, so mid("abc", 2, 1) returns b.
 
you really want something that uses instr as this will return a location. 
or better yet, look in an array, probably way easier
 
stringvar array lines := split({table.field}, chr(13)+chr(10));
stringvar result:="";
numbervar i;
for i:=1 to ubound(lines) Do
(
  if left(lines, 12) = "Staff Member" then
    result = result + lines +chr(13) +chr(10);
);
 
""//hide the output, remove this if you want to see what has been selected
 
this takes your field and breaks it up into lines based on the CR/LF which is at the end of each line. It then checks if there are any lines. If so, it looks at each line and checks if it starts with Staff Member, if so, it adds it to the results.
 
HTH
 
IP IP Logged
Jaelle
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote Jaelle Replybullet Posted: 14 Oct 2009 at 7:52am
Thanks, just entered it now, but when I get Crystal to check it, it highlights the bold text 

(
    if left (lines, 12) = "Staff Member" then
        result = result + lines + chr(13) + chr(10);
);

and returns "This array must be subscripted.  For example: Array ."
 
Any idea where I need to do this (I've never got my head round variablesEmbarrassed)
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Oct 2009 at 8:10am
lines is an array, left off the index...should be 'lines' in both that line and the next.
IP IP Logged
Jaelle
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote Jaelle Replybullet Posted: 14 Oct 2009 at 8:17am
Sorry, I'm being really thick, I don't understand which line?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Oct 2009 at 8:19am
 if left (lines, 12) = "Staff Member" then
        result = result + lines + chr(13) + chr(10);
IP IP Logged
Jaelle
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote Jaelle Replybullet Posted: 14 Oct 2009 at 8:24am
Nope, that's what was there & I just copied & pasted yours in paranoia & still getting the same errorUnhappy
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Oct 2009 at 10:01am
ok, I read what I type, not what is displayed.  ....AH, that is why everything goes to italics.
 
Here is what is needed.
if left (lines'square bracket i close square brack', 12) = "Staff Member" then
        result = result + lines'square bracket i close square bracket' + chr(13) + chr(10);

 

if you had looked in help for arrays you would have seen that the array is accessed via the index which is enclosed in square brackets.


IP IP Logged
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