Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Many thanks to you for putting it together and to the forum members for taking the time to post their replies and give their time to help others. Their isn't another site that can touch it..."

Geography

Where in the world do Tek-Tips members come from?
mtownbound (TechnicalUser)
9 May 12 8:43
I have a memo field that contains multiple lines of text that I need to split. I understand the "string" [3 to 5] method but should I use stringvar to pull multiple lines? Here's a sample of the memo field:

Date: 20120509
Location: New York, NY
Institution: Wells Fargo

I need to be able to extract the values for each line.


Thanks!!!
Charliy (Programmer)
9 May 12 10:03
If it's already breaking into lines like that when you print it, then you can look for chr(10) or chr(13) as breakpoints.
mtownbound (TechnicalUser)
9 May 12 10:09
But if I want to capture "New York, NY" how do I tell it to trim at the end of the row that starts with "Location:"?
CoSpringsGuy (IS/IT--Management)
9 May 12 10:19
Are date: Location: and Intstitution: the only three items always found in the memo field and are they always there?
Do you need these returned as seperate fields?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 10:29
Yes, the field labels will always be the same label and length, but the position may not be the same because there's a description field before those fields. For example:

Row_ID: 10456
Description: This is just a test of the field
Date: 20120509
Location: New York, NY
Institution: Wells Fargo

Row_ID: 10457
Description: This is just a test of the information that was previously archived but has been restored.
Date: 20120510
Location: Miami, FL
Institution: Bank of America
 
CoSpringsGuy (IS/IT--Management)
9 May 12 10:38
but you only want those three items removed (without  labels) from the memo field? and you do want them as seperate fields?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 10:44
That's exactly what I need.  
CoSpringsGuy (IS/IT--Management)
9 May 12 10:47
k you will need to find out if the break is a chr(10) or chr(13) so try this:

mDate formula

local stringvar array a := split({yourmemofield},chr(13));
local stringvar b;
b := replace(a[3],"Date: ","");
local datevar mDate :=
date(
tonumber(mid(b,1,4)),
    tonumber(mid(b,5,2)),
    tonumber(mid(b,7,2))
);

i took the liberty of converting the date to an actual date field as well. If that doesnt work change the CHR(13) in the split function to chr(10)

once that works for you

mLocation formula
local stringvar array a := split({@test},chr(13));
local stringvar mLocation := replace(a[4],"Location: ","");

mInstitition formula

local stringvar array a := split({@test},chr(13));
local stringvar mInstitution := replace(a[5],"Institution: ","");


 

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

CoSpringsGuy (IS/IT--Management)
9 May 12 10:48
change {@test} in the last two formulas to your memfield from database...

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 11:06
The formula is okay, but when I preview, I'm getting the following error:

"A subscript must be between 1 and the size of the array."  
mtownbound (TechnicalUser)
9 May 12 11:12
CoSprings, I need to update my example. It looked right in the window, but not in the post:

Row_ID: 10456
Description: This is just a test of the field
Date: 20120509
Location: New York, NY
Institution: Wells Fargo

Row_ID: 10457
Description: This is just a test of the information that was
previously archived but has been restored.
Date: 20120510
Location: Miami, FL
Institution: Bank of America

Notice how the multi-line Description changes the row of Date, Location, etc.
  
CoSpringsGuy (IS/IT--Management)
9 May 12 11:13
ahhh ok that sucks! lol .. ok i am in a meeting but we can still fix that.. I will get back to you .. did you determine if it was chr(10) or chr(13)?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 11:22
It's a chr(13).
CoSpringsGuy (IS/IT--Management)
9 May 12 11:53
date formula - let me know how that works for you and I will do the rest .. boring meeting but I have to pretend Im paying attention

local stringvar  a := replace({youmemofield},chr(13),"");
local stringvar b := mid(a,instr(a,"Date:")+6,8);
local datevar mDate :=
date(
tonumber(mid (b,1,4)),
    tonumber(mid (b,5,2)),
    tonumber(mid (b,7,2))
);
mDate  

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

CoSpringsGuy (IS/IT--Management)
9 May 12 12:03
Location formula
local stringvar  a := replace({yourfield},chr(13),"");
local numbervar b := instr(a,"Institution:");
local numbervar c := instr(a,"Location:")+10;
local stringvar mLocation := mid(a,c,(b-c));
mLocation

Institution Formula
local stringvar  a := replace({yourfield},chr(13),"");
local numbervar b := instr(a,"Institution:")+13;
local stringvar mLocation := mid(a,b);
mLocation

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 12:19
They work, but they're also pulling everything after the desired field. For example, @Location returns:

Miami, FL
Institution: Bank of America

 
CoSpringsGuy (IS/IT--Management)
9 May 12 12:26
did you copy my formula or retype. The only way I see that happening is if you didnt spell Institution  in the line "local numbervar b := instr(a,"Institution:");" exactly as it would appear in the memo field  

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
9 May 12 12:56
I copied and changed the fields, but I'm still testing.  
mtownbound (TechnicalUser)
9 May 12 13:04
I got it!! Thanks!!!!
lbass (TechnicalUser)
9 May 12 21:47
stringvar p := {table.memo};
stringvar array q := split(p,chr(13));
mid(q[4],instr(q[4],": ")+2); //4th line

-LB
CoSpringsGuy (IS/IT--Management)
9 May 12 21:59
LB -

I like yours better .. I had initially started using split but my mind went a different direction and it worked so i stopped..

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

 

mtownbound (TechnicalUser)
10 May 12 8:58
Thanks lbass, but what if the line number is moved by the text in the memo field? Say instead of the 4th line, now the "Location" is on the 7th line?
mtownbound (TechnicalUser)
10 May 12 10:31

lbass, I also received the error when I used the formula:

"A subscript must be between 1 and the size of the array."

CoSpringsGuy (IS/IT--Management)
10 May 12 14:01

thats because of the unknown amount of chr(13) encountered if the description is several lines long. Thats why I just stripped those characters (chr(13)) and searched for the field names you were looking for. Is it still working correctly?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

mtownbound (TechnicalUser)
10 May 12 15:00

Of course not, lol. I tried the other formula and I got the subscript error, but when I switched back, I still get the error. Here's what I'm using:

local stringvar a := replace({table.memo},chr(13),"");
local numbervar b := instr(a,"Institution:");
local numbervar c := instr(a,"Location:")+14;
local stringvar mLocation := mid(a,c,(b-c));
mLocation

mtownbound (TechnicalUser)
10 May 12 15:05

Of course not, lol. I tried the other formula and I got the subscript error, but when I switched back, I still get the error. Here's what I'm using:

local stringvar a := replace({table.memo},chr(13),"");
local numbervar b := instr(a,"Institution:");
local numbervar c := instr(a,"Location:")+14;
local stringvar mLocation := mid(a,c,(b-c));
mLocation

CoSpringsGuy (IS/IT--Management)
10 May 12 15:37

so whats the error that you get with that code? I noticed you added 14 instead of 10 on the third line. By doing this you will cut off the first 4 digits of your city I believe.

is the error "String length less than zero or not an integer?"

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

mtownbound (TechnicalUser)
10 May 12 15:47

Yes, that's the error, the subscript error was from earlier. I changed the 14 back to 10.

Helpful Member!  CoSpringsGuy (IS/IT--Management)
10 May 12 15:52

local stringvar a := replace({table.memo},chr(13),"");
local numbervar b := instr(a,"Institution:");
local numbervar c := instr(a,"Location:")+10;
local stringvar mLocation ;
if b>c then
MLocation := mid(a,c,(b-c));


mLocation

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

Helpful Member!  lbass (TechnicalUser)
10 May 12 22:19

stringvar p := {table.memo};
stringvar array q := split(p,chr(13));
if ubound(q)>=4 then
mid(q[4],instr(q[4],": ")+2); //4th line

-LB

mtownbound (TechnicalUser)
11 May 12 8:40

Great news! I got both to work flawlessly!! Thanks for all your assistance guys!!

mtownbound (TechnicalUser)
11 May 12 9:53

And I thought I was done.....

Maybe I should start a new thread, but I have a Notes section, at the bottom of the memo field, that is being trimmed on the second row as if there's a character limit on the field. The entire entry is displayed in the database, but not in the report. Any ideas?

andymc (Vendor)
11 May 12 15:16
You might try right-clicking, Format, the field and on the Main tab, click Can Grow.
mtownbound (TechnicalUser)
11 May 12 15:23
Thanks andymc, "can grow" is already checked.
CoSpringsGuy (IS/IT--Management)
11 May 12 15:26
in field explorer, right click and select show field type... see how many characters it shows and see if that corresponds with your database field

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

mtownbound (TechnicalUser)
11 May 12 15:39
It just says "memo" field.
CoSpringsGuy (IS/IT--Management)
11 May 12 15:42
"Maybe I should start a new thread, but I have a Notes section, at the bottom of the memo field, that is being trimmed on the second row as if there's a character limit on the field. The entire entry is displayed in the database, but not in the report. Any ideas? "

what do you mean by "at the bottom of the memo field"?

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

mtownbound (TechnicalUser)
11 May 12 15:48
Here are the rows. In addition to a few other lines in the memo field, there's a "Notes" line, as well. This section is the one that's being cut off at the same position, even before I use your formula to split the text.

Row_ID: 10456
Description: This is just a test of the field
Date: 20120509
Location: New York, NY
Institution: Wells Fargo
Notes:TestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestData

Row_ID: 10457
Description: This is just a test of the information that was previously archived but has been restored.
Date: 20120510
Location: Miami, FL
Institution: Bank of America
Notes:TestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestDataTestData

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close