Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Parsing Memo fields Post Reply Post New Topic
Author Message
Bernieo
Newbie
Newbie
Avatar

Joined: 06 Aug 2013
Location: United States
Online Status: Offline
Posts: 5
Quote Bernieo Replybullet Topic: Parsing Memo fields
     Posted: 06 Aug 2013 at 11:03am
I am trying to parse data out of a Memo field using crystal reports 2008.

This is what I am using:

whileprintingrecords;
numbervar v_start;
numbervar v_end;

v_start := instr({YourMemoField},"Aspirin");
v_end := instr(mid({YourMemoField}, v_start + 7),chr(10)); // carriage return chr(13)

if {YourMemoField} like ["Aspirin*"] then mid({YourMemoField},v_start,(6 + v_end)) else ""


It works as far as getting the word aspirin and I have played with it enough to get more data or less data, but what I really want is the data behind the word aspirin which will be a date.   So it will look like this:

Aspirin: 01/01/2013 ( i only want to retrieve the date)

any ideas on how to do this.. I know i have to find the line of data saying aspirin but cannot pull anything after that word without getting Aspirin in it.. If I dont use the v-start, than it uses data from the first line in the Memo field... I hope I'm making sense.

Not all records will have the Word Aspirin in them. so it needs to deal with this also,

Thanks




Edited by Bernieo - 06 Aug 2013 at 11:13am
Benie
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Aug 2013 at 3:37am

If a record does have 'aspirin' in it does it always have a date following it and if so is it always in the mm/dd/yyyy format and are there lead and trailing spaces? or is the date just somewhere after 'aspirin' but on the same line, hence your use of chr(10)?

IP IP Logged
Bernieo
Newbie
Newbie
Avatar

Joined: 06 Aug 2013
Location: United States
Online Status: Offline
Posts: 5
Quote Bernieo Replybullet Posted: 07 Aug 2013 at 1:51pm
We are now looking for Colonoscopy: instead of Aspirin.

if the record does have Colonoscopy: in it .. there will
always be a date in MM/DD/YYYY format. And will have a space after the : ex. ASA Colonoscopy:spacemm/dd/yyyy.   But no space after it. I was trying different things to get the date to pull so the Chr(10) may not need to be in there.

And this might still change, so if you could explain each line, so if I do need to search for something else I can make the changes that would be great.. User has not yet decided for sure what they want to have before the date. I do know the format will be consistent and the space will be after the words I need to search for..
Benie
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2013 at 4:33am
since you are unclear on the word they want to use my guess is they will want to be able to pick the word when they run it.
This allows them to do that
 
whileprintingrecords;
numbervar v_start;
stringvar param;
numbervar paramlen;
stringvar result;
param := trim({?Word});
paramlen := len(param) + 2 ;
v_start := instr({table.memo},param);
result := if v_start=0 then 'Word not found' else mid({table.memo},v_start + paramlen,10);
result
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2013 at 4:39am
I forgot to mention that you will need to create a string parameter to let the user input the desired search.
The example I gave is a parameter called "Word" which appears in the formula as {?Word}. you can name it whatever you want.


Edited by DBlank - 08 Aug 2013 at 4:40am
IP IP Logged
Bernieo
Newbie
Newbie
Avatar

Joined: 06 Aug 2013
Location: United States
Online Status: Offline
Posts: 5
Quote Bernieo Replybullet Posted: 08 Aug 2013 at 7:18am
Thank you I will give this a shot.. the word will remain constant. LOL but for now the final decision has not been made.. But I should just be able to replace the {?Word} with word I need correct? Such as 'COLONOSCOPY:'
Benie
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2013 at 7:33am
you can set the word in the formula do not use the : though. It is accounted for in the len portion of the formula (+2).
If you need to use it make the paramlen use +1
 
whileprintingrecords;
numbervar v_start;
stringvar param;
numbervar paramlen;
stringvar result;
param := "colonoscopy";
paramlen := len(param) + 2 ;
v_start := instr({table.memo},param);
result := if v_start=0 then 'Word not found' else mid({table.memo},v_start + paramlen,10);
result
 


Edited by DBlank - 08 Aug 2013 at 7:34am
IP IP Logged
Bernieo
Newbie
Newbie
Avatar

Joined: 06 Aug 2013
Location: United States
Online Status: Offline
Posts: 5
Quote Bernieo Replybullet Posted: 08 Aug 2013 at 8:26am
Thank you very much - I will give it a try and let you know how it goes.
Benie
IP IP Logged
Bernieo
Newbie
Newbie
Avatar

Joined: 06 Aug 2013
Location: United States
Online Status: Offline
Posts: 5
Quote Bernieo Replybullet Posted: 08 Aug 2013 at 12:38pm
Thank you again! This worked and I was able to use it in multiple formulas to get data out of the memo field.
Benie
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