Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ToTrim

Status
Not open for further replies.

BROWNIE56

Programmer
Dec 28, 2000
31
US
Our name field prints the lastnamefirst name in one field.

How would I print the first 20 characters of the last name followed by 5 spaces then print the first 15 characters of the first name?

Thanks,

Sharon
 
You did not say where in the string the first name begins, so I cannot help you. I need to know where it begins, and what happens if you have a very short last name like "Woo"? Does the first name begin at character # 4 ? Or is it padded with X number of spaces?

Please advise Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
The field is a 50 character varchar

Our users type in the name such as:

Brown, Sharon
Brown Sharon
BrownSharon

What I have to do it print, on a dot matrix form, the last name then the first name.

There is room for 20 characters for the last name and a few blank spaces then room for 15 characters for the first name.

 
So there is not consistency to the first and last names? It is possible to test for the existence of a comma or a space and separate the string -- this is done with the Instr() function -- but I know of no way to separate the string if there is nothing to indicate where the separation is.

Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
The only way to separate them the way you have shown us is if we are garuanteed that the first name begins with a capital letter...we can find that.

Is the reason for the mandatory 20 chars of Last name + 5 chars of spaces so that the First names line up?? This won't happen unless you use a courier font. I would recommend a formula field then 2 display fields...then there is no alignment problem

@GetLastnameFirstname
WhilePrintingRecords;
stringVar temp := {table.lastnamefirstname};
stringVar firstName := "";
stringVar lastName := "";
numberVar i;

//strip out the commas and any blanks

temp := replace(temp," ","");
temp := replace(temp,",","");

//start test at second char for the first capital
for i := 2 to Length(temp) do
(
if asc(temp) in [65 to 90] then
(
if i > 20 then
firstName := temp[1 to 20]
else
firstName := temp[1 to i-1];
if length(temp) - i + 1 > 15 then
lastName := temp[i to i+14]
else
lastName := temp[i to length(temp)];
exit for;
);
);

//do something if there are no capitals
if firstName := "" then
(
firstName := left(temp,20);
lastName := right(temp,15);
);


then the display formulas

@Display Firstname
WhilePrintingRecords;
evaluateafter({@GetLastnameFirstname})
stringVar firstName ;

firstName ;

@Display Lastname
WhilePrintingRecords;
evaluateafter({@GetLastnameFirstname})
stringVar lastName ;

lastName ;


put all 3 formulas in the detail section but suppress the
@GetLastnameFirstname formula and space the other 2 display formulas appropriately.

This is the best I can do...even then this formula won't handle hyphenated lastnames...I suppose it could if I tested for them...then ignored the next capital letter...but I'll let you figure that out :)

Hope this helps;


Jim

JimBroadbent@Hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top